An implementation of the SM2 2023 cryptographic suite for Data Integrity, compliant with W3C standards and optimized for both Node.js and browser environments.
The SM2 2023 Cryptographic Suite provides a standards-compliant implementation for:
- Data Integrity Proofs: Create and verify proofs using SM2 signatures
- Document Canonicalization: URDNA2015 algorithm implementation
- SM2/SM3: Signature generation and verification using SM2 with SM3 digest
- Cross-Platform: Consistent behavior across Node.js and browsers
- Complete SM2 2023 cryptographic suite implementation
- W3C Data Integrity 1.0 compatibility
- URDNA2015 document canonicalization
- Pluggable key management support
- Comprehensive error handling
- GB/T 32918.1-2016: SM2 Elliptic Curve Digital Signature Algorithm
- GB/T 32905-2016: SM3 Cryptographic Hash Algorithm
- Data Integrity 1.0
- Proof creation and verification
- Document canonicalization
- Signature suite specification
npm install @instun/sm2-2023-cryptosuite
import { cryptosuite } from '@instun/sm2-2023-cryptosuite';
// Initialize suite with a key
const suite = {
...cryptosuite,
signer: () => key.signer(),
verifier: () => key.verifier()
};
// Create a proof
const proof = await createProof({
document,
suite,
purpose
});
// Verify a proof
const result = await verifyProof({
document,
proof,
suite,
purpose
});
Core implementation of the SM2 2023 cryptographic suite.
name
: 'sm2-2023'requiredAlgorithm
: 'SM2'
Canonicalizes a JSON-LD document.
- Parameters:
input
(Object|string): JSON-LD documentoptions
(Object, optional): Canonicalization options
- Returns: Promise Canonicalized document
Creates a verifier for SM2 signatures.
- Parameters:
options.verificationMethod
(Object): Verification method object
- Returns: Verifier object with verify() method
The module provides specific error types:
ArgumentError
: Invalid argument errorsFormatError
: Format conversion errorsCryptoError
: Cryptographic operation errors
Each error includes:
- Descriptive message
- Error code
- Original error cause (when applicable)
- Node.js 16.x or later
- Modern browsers with ES6+ support
Copyright (c) 2024 Instun, Inc. All rights reserved.