@did-btcr2/common 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +373 -0
- package/README.md +3 -0
- package/dist/cjs/canonicalization.js +163 -0
- package/dist/cjs/canonicalization.js.map +1 -0
- package/dist/cjs/constants.js +116 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/errors.js +151 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/exts.js +182 -0
- package/dist/cjs/exts.js.map +1 -0
- package/dist/cjs/index.js +10 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/interfaces.js +2 -0
- package/dist/cjs/interfaces.js.map +1 -0
- package/dist/cjs/logger.browser.js +77 -0
- package/dist/cjs/logger.browser.js.map +1 -0
- package/dist/cjs/logger.js +139 -0
- package/dist/cjs/logger.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/patch.js +163 -0
- package/dist/cjs/patch.js.map +1 -0
- package/dist/cjs/types.js +20 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/canonicalization.js +163 -0
- package/dist/esm/canonicalization.js.map +1 -0
- package/dist/esm/constants.js +116 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/errors.js +151 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/exts.js +182 -0
- package/dist/esm/exts.js.map +1 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/interfaces.js +2 -0
- package/dist/esm/interfaces.js.map +1 -0
- package/dist/esm/logger.browser.js +77 -0
- package/dist/esm/logger.browser.js.map +1 -0
- package/dist/esm/logger.js +139 -0
- package/dist/esm/logger.js.map +1 -0
- package/dist/esm/patch.js +163 -0
- package/dist/esm/patch.js.map +1 -0
- package/dist/esm/types.js +20 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/types/canonicalization.d.ts +106 -0
- package/dist/types/canonicalization.d.ts.map +1 -0
- package/dist/types/constants.d.ts +103 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/errors.d.ts +113 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/exts.d.ts +82 -0
- package/dist/types/exts.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/interfaces.d.ts +282 -0
- package/dist/types/interfaces.d.ts.map +1 -0
- package/dist/types/logger.browser.d.ts +28 -0
- package/dist/types/logger.browser.d.ts.map +1 -0
- package/dist/types/logger.d.ts +45 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/patch.d.ts +63 -0
- package/dist/types/patch.d.ts.map +1 -0
- package/dist/types/types.d.ts +104 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +109 -0
- package/src/canonicalization.ts +180 -0
- package/src/constants.ts +123 -0
- package/src/errors.ts +224 -0
- package/src/exts.ts +293 -0
- package/src/index.ts +11 -0
- package/src/interfaces.ts +311 -0
- package/src/logger.browser.ts +92 -0
- package/src/logger.ts +162 -0
- package/src/patch.ts +181 -0
- package/src/rdf-canonize.d.ts +6 -0
- package/src/types.ts +113 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { sha256 } from '@noble/hashes/sha2';
|
|
2
|
+
import { bytesToHex } from '@noble/hashes/utils';
|
|
3
|
+
import { canonicalize as jcsa } from 'json-canonicalize';
|
|
4
|
+
import { base58btc } from 'multiformats/bases/base58';
|
|
5
|
+
import rdf from 'rdf-canonize';
|
|
6
|
+
import { CanonicalizationAlgorithm, HashBytes, JSONObject } from './types.js';
|
|
7
|
+
import { CanonicalizationError } from './errors.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Canonicalization class provides methods for canonicalizing JSON objects
|
|
11
|
+
* and hashing them using SHA-256. It supports different canonicalization
|
|
12
|
+
* algorithms and encoding formats (hex and base58).
|
|
13
|
+
* @class Canonicalization
|
|
14
|
+
* @type {Canonicalization}
|
|
15
|
+
*/
|
|
16
|
+
export class Canonicalization {
|
|
17
|
+
private _algorithm: CanonicalizationAlgorithm;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Initializes the Canonicalization class with the specified algorithm.
|
|
21
|
+
* @param {CanonicalizationAlgorithm} algorithm The canonicalization algorithm to use ('jcs' or 'rdfc').
|
|
22
|
+
*/
|
|
23
|
+
// TODO: Need to move to using RDFC by default
|
|
24
|
+
constructor(algorithm: CanonicalizationAlgorithm = 'jcs') {
|
|
25
|
+
this._algorithm = algorithm;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Sets the canonicalization algorithm.
|
|
30
|
+
* @param {'jcs' | 'rdfc'} algorithm Either 'jcs' or 'rdfc'.
|
|
31
|
+
*/
|
|
32
|
+
set algorithm(algorithm: 'jcs' | 'rdfc') {
|
|
33
|
+
// Normalize the passed algorithm to lowercase
|
|
34
|
+
algorithm = algorithm.toLowerCase() as CanonicalizationAlgorithm;
|
|
35
|
+
|
|
36
|
+
// Validate the algorithm is either 'jcs' or 'rdfc'
|
|
37
|
+
if(!['jcs', 'rdfc'].includes(algorithm)){
|
|
38
|
+
throw new CanonicalizationError(`Unsupported algorithm: ${algorithm}`, 'ALGORITHM_ERROR');
|
|
39
|
+
}
|
|
40
|
+
// Set the algorithm
|
|
41
|
+
this._algorithm = algorithm;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Gets the canonicalization algorithm.
|
|
46
|
+
* @returns {CanonicalizationAlgorithm} The current canonicalization algorithm.
|
|
47
|
+
*/
|
|
48
|
+
get algorithm(): CanonicalizationAlgorithm {
|
|
49
|
+
return this._algorithm;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Implements {@link http://dcdpr.github.io/did-btcr2/#json-canonicalization-and-hash | 9.2 JSON Canonicalization and Hash}.
|
|
54
|
+
*
|
|
55
|
+
* A macro function that takes in a JSON document, document, and canonicalizes it following the JSON Canonicalization
|
|
56
|
+
* Scheme. The function returns the canonicalizedBytes.
|
|
57
|
+
*
|
|
58
|
+
* Optionally encodes a sha256 hashed canonicalized JSON object.
|
|
59
|
+
* Step 1 Canonicalize (JCS/RDFC) → Step 2 Hash (SHA256) → Step 3 Encode (Hex/Base58).
|
|
60
|
+
*
|
|
61
|
+
* @param {JSONObject} object The object to process.
|
|
62
|
+
* @param {string} encoding The encoding format ('hex' or 'base58').
|
|
63
|
+
* @returns {Promise<string>} The final SHA-256 hash bytes as a hex string.
|
|
64
|
+
*/
|
|
65
|
+
public async process(object: JSONObject, encoding: string = 'hex'): Promise<string> {
|
|
66
|
+
// Step 1: Canonicalize
|
|
67
|
+
const canonicalized = await this.canonicalize(object);
|
|
68
|
+
// Step 2: Hash
|
|
69
|
+
const hashed = this.hash(canonicalized);
|
|
70
|
+
// Step 3: Encode
|
|
71
|
+
const encoded = this.encode(hashed, encoding);
|
|
72
|
+
// Return the encoded string
|
|
73
|
+
return encoded;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Step 1: Uses this.algorithm to determine the method (JCS/RDFC).
|
|
78
|
+
* @param {JSONObject} object The object to canonicalize.
|
|
79
|
+
* @returns {Promise<string>} The canonicalized object.
|
|
80
|
+
*/
|
|
81
|
+
public async canonicalize(object: JSONObject): Promise<string> {
|
|
82
|
+
return await (this[this.algorithm] as (object: JSONObject) => any)(object);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Step 1: Canonicalizes an object using JCS (JSON Canonicalization Scheme).
|
|
87
|
+
* @param {JSONObject} object The object to canonicalize.
|
|
88
|
+
* @returns {string} The canonicalized object.
|
|
89
|
+
*/
|
|
90
|
+
public jcs(object: JSONObject): any {
|
|
91
|
+
return jcsa(object);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Step 1: Canonicalizes an object using RDF Canonicalization (RDFC).
|
|
96
|
+
* @param {JSONObject} object The object to canonicalize.
|
|
97
|
+
* @returns {Promise<string>} The canonicalized object.
|
|
98
|
+
*/
|
|
99
|
+
public rdfc(object: JSONObject): Promise<string> {
|
|
100
|
+
return rdf.canonize([object], { algorithm: 'RDFC-1.0' });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Step 2: SHA-256 hashes a canonicalized object.
|
|
105
|
+
* @param {string} canonicalized The canonicalized object.
|
|
106
|
+
* @returns {HashBytes} The SHA-256 HashBytes (Uint8Array).
|
|
107
|
+
*/
|
|
108
|
+
public hash(canonicalized: string): HashBytes {
|
|
109
|
+
return sha256(canonicalized);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Step 3: Encodes SHA-256 hashed, canonicalized object as a hex or base58 string.
|
|
114
|
+
* @param {string} canonicalizedhash The canonicalized object to encode.
|
|
115
|
+
* @param {string} encoding The encoding format ('hex' or 'base58').
|
|
116
|
+
* @throws {CanonicalizationError} If the encoding format is not supported.
|
|
117
|
+
* @returns {string} The encoded string.
|
|
118
|
+
*/
|
|
119
|
+
public encode(canonicalizedhash: HashBytes, encoding: string = 'hex'): string {
|
|
120
|
+
switch(encoding) {
|
|
121
|
+
case 'hex':
|
|
122
|
+
return this.hex(canonicalizedhash);
|
|
123
|
+
case 'base58':
|
|
124
|
+
return this.base58(canonicalizedhash);
|
|
125
|
+
default:
|
|
126
|
+
throw new CanonicalizationError(`Unsupported encoding: ${encoding}`, 'ENCODING_ERROR');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Step 3.1: Encodes HashBytes (Uint8Array) to a hex string.
|
|
132
|
+
* @param {HashBytes} hashBytes The hash as a Uint8Array.
|
|
133
|
+
* @returns {string} The hash as a hex string.
|
|
134
|
+
*/
|
|
135
|
+
public hex(hashBytes: HashBytes): string {
|
|
136
|
+
return bytesToHex(hashBytes);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Step 3.2: Encodes HashBytes (Uint8Array) to a base58btc string.
|
|
141
|
+
* @param {HashBytes} hashBytes The hash as a Uint8Array.
|
|
142
|
+
* @returns {string} The hash as a hex string.
|
|
143
|
+
*/
|
|
144
|
+
public base58(hashBytes: HashBytes): string {
|
|
145
|
+
return base58btc.encode(hashBytes);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Canonicalizes an object, hashes it and returns it as hash bytes.
|
|
150
|
+
* Step 1-2: Canonicalize → Hash.
|
|
151
|
+
* @param {JSONObject} object The object to process.
|
|
152
|
+
* @returns {Promise<HashBytes>} The final SHA-256 hash bytes.
|
|
153
|
+
*/
|
|
154
|
+
public async canonicalhash(object: JSONObject): Promise<HashBytes> {
|
|
155
|
+
const canonicalized = await this.canonicalize(object);
|
|
156
|
+
return this.hash(canonicalized);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Computes the SHA-256 hash of a canonicalized object and encodes it as a hex string.
|
|
161
|
+
* Step 2-3: Hash → Encode(Hex).
|
|
162
|
+
* @param {string} canonicalized The canonicalized object to hash.
|
|
163
|
+
* @returns {string} The SHA-256 hash as a hex string.
|
|
164
|
+
*/
|
|
165
|
+
public hashhex(canonicalized: string): string {
|
|
166
|
+
return this.encode(this.hash(canonicalized));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Computes the SHA-256 hashes of canonicalized object and encodes it as a base58 string.
|
|
171
|
+
* Step 2-3: Hash → Encode(base58).
|
|
172
|
+
* @param {string} canonicalized The canonicalized object to hash.
|
|
173
|
+
* @returns {string} The SHA-256 hash as a base58 string.
|
|
174
|
+
*/
|
|
175
|
+
public hashb58(canonicalized: string): string {
|
|
176
|
+
return this.encode(this.hash(canonicalized), 'base58');
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export const canonicalization = new Canonicalization();
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { sha256 } from '@noble/hashes/sha2';
|
|
2
|
+
import { Bytes, HashHex } from './types.js';
|
|
3
|
+
|
|
4
|
+
export const ID_PLACEHOLDER_VALUE = 'did:btcr2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
|
|
5
|
+
export const OP_RETURN = 0x6a;
|
|
6
|
+
export const OP_PUSH32 = 0x20;
|
|
7
|
+
export const VALID_HRP = ['k', 'x'];
|
|
8
|
+
export const MULTIBASE_URI_PREFIX = 'urn:mb:';
|
|
9
|
+
export const INITIAL_BLOCK_REWARD = 50;
|
|
10
|
+
export const HALVING_INTERVAL = 150;
|
|
11
|
+
export const COINBASE_MATURITY_DELAY = 100;
|
|
12
|
+
export const POLAR_BOB_CLIENT_CONFIG = {
|
|
13
|
+
username : 'polaruser',
|
|
14
|
+
password : 'polarpass',
|
|
15
|
+
host : 'http://127.0.0.1:18443',
|
|
16
|
+
allowDefaultWallet : true,
|
|
17
|
+
version : '28.1.0'
|
|
18
|
+
};
|
|
19
|
+
export const POLAR_ALICE_CLIENT_CONFIG = {
|
|
20
|
+
username : 'polaruser',
|
|
21
|
+
password : 'polarpass',
|
|
22
|
+
host : 'http://127.0.0.1:18444',
|
|
23
|
+
allowDefaultWallet : true,
|
|
24
|
+
version : '28.1.0'
|
|
25
|
+
};
|
|
26
|
+
export const DEFAULT_REST_CONFIG = { host: 'http://localhost:3000' };
|
|
27
|
+
export const DEFAULT_RPC_CONFIG = POLAR_BOB_CLIENT_CONFIG;
|
|
28
|
+
export const DEFAULT_BLOCK_CONFIRMATIONS = 7;
|
|
29
|
+
|
|
30
|
+
// Fixed public key header bytes per the Data Integrity BIP340 Cryptosuite spec: [0xe7, 0x01] / [231, 1]
|
|
31
|
+
export const BIP340_PUBLIC_KEY_MULTIBASE_PREFIX: Bytes = new Uint8Array([0xe7, 0x01]);
|
|
32
|
+
// Hash of the BIP-340 Multikey prefix
|
|
33
|
+
export const BIP340_PUBLIC_KEY_MULTIBASE_PREFIX_HASH: HashHex = Buffer.from(sha256(BIP340_PUBLIC_KEY_MULTIBASE_PREFIX)).toString('hex');
|
|
34
|
+
// Fixed secret key header bytes per the Data Integrity BIP340 Cryptosuite spec: [0x81, 0x26] / [129, 38]
|
|
35
|
+
export const BIP340_SECRET_KEY_MULTIBASE_PREFIX: Bytes = new Uint8Array([0x81, 0x26]);
|
|
36
|
+
// Hash of the BIP-340 Multikey prefix
|
|
37
|
+
export const BIP340_SECRET_KEY_MULTIBASE_PREFIX_HASH: HashHex = Buffer.from(sha256(BIP340_SECRET_KEY_MULTIBASE_PREFIX)).toString('hex');
|
|
38
|
+
// curve's field size
|
|
39
|
+
export const B256 = 2n ** 256n;
|
|
40
|
+
// curve's field prime
|
|
41
|
+
export const P = B256 - 0x1000003d1n;
|
|
42
|
+
// curve (group) order
|
|
43
|
+
export const N = B256 - 0x14551231950b75fc4402da1732fc9bebfn;
|
|
44
|
+
// base point x
|
|
45
|
+
export const Gx = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n;
|
|
46
|
+
// base point y
|
|
47
|
+
export const Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n;
|
|
48
|
+
// curve parameters
|
|
49
|
+
export const a = 0n;
|
|
50
|
+
export const b = 7n;
|
|
51
|
+
export const p = P;
|
|
52
|
+
export const n = N;
|
|
53
|
+
export const CURVE = {
|
|
54
|
+
p,
|
|
55
|
+
n,
|
|
56
|
+
a,
|
|
57
|
+
b,
|
|
58
|
+
Gx,
|
|
59
|
+
Gy
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const W3C_DID_V1 = 'https://www.w3.org/ns/did/v1';
|
|
63
|
+
export const W3C_DID_V1_1 = 'https://www.w3.org/TR/did-1.1';
|
|
64
|
+
export const W3C_DATA_INTEGRITY_V1 = 'https://w3id.org/security/data-integrity/v1';
|
|
65
|
+
export const W3C_DATA_INTEGRITY_V2 = 'https://w3id.org/security/data-integrity/v2';
|
|
66
|
+
export const W3C_SECURITY_V2 = 'https://w3id.org/security/v2';
|
|
67
|
+
export const BTC1_METHOD_CONTEXT = 'https://btcr2.dev/context/v1';
|
|
68
|
+
export const W3C_ZCAP_V1 = 'https://w3id.org/zcap/v1';
|
|
69
|
+
export const W3C_JSONLD_PATCH_V1 = 'https://w3id.org/json-ld-patch/v1';
|
|
70
|
+
export const W3C_MULTIKEY_V1 = 'https://w3id.org/security/multikey/v1';
|
|
71
|
+
export const W3C_DID_RESOLUTION_V1 = 'https://w3id.org/did-resolution/v1';
|
|
72
|
+
export const CONTEXT_URL_MAP = {
|
|
73
|
+
w3c : {
|
|
74
|
+
did : {
|
|
75
|
+
v1 : 'https://www.w3.org/ns/did/v1',
|
|
76
|
+
v1_1 : 'https://www.w3.org/TR/did-1.1',
|
|
77
|
+
},
|
|
78
|
+
didresolution : {
|
|
79
|
+
v1 : 'https://w3id.org/did-resolution/v1',
|
|
80
|
+
},
|
|
81
|
+
security : {
|
|
82
|
+
v2 : 'https://w3id.org/security/v2',
|
|
83
|
+
},
|
|
84
|
+
dataintegrity : {
|
|
85
|
+
v1 : 'https://w3id.org/security/data-integrity/v1',
|
|
86
|
+
v2 : 'https://w3id.org/security/data-integrity/v2',
|
|
87
|
+
},
|
|
88
|
+
zcap : {
|
|
89
|
+
v1 : 'https://w3id.org/zcap/v1',
|
|
90
|
+
},
|
|
91
|
+
jsonldpatch : {
|
|
92
|
+
v1 : 'https://w3id.org/json-ld-patch/v1',
|
|
93
|
+
},
|
|
94
|
+
multikey : {
|
|
95
|
+
v1 : 'https://w3id.org/security/multikey/v1',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
btcr2 : {
|
|
99
|
+
diddocument : {
|
|
100
|
+
v1 : 'https://dcdpr.github.io/did-btcr2-js/ns/did-document/v1',
|
|
101
|
+
},
|
|
102
|
+
method : {
|
|
103
|
+
v1 : 'https://btcr2.dev/context/v1'
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export const BTC1_DID_DOCUMENT_CONTEXT = [
|
|
110
|
+
CONTEXT_URL_MAP.w3c.did.v1_1,
|
|
111
|
+
CONTEXT_URL_MAP.btcr2.method.v1,
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
export const BTC1_MULTIKEY_CONTEXT = [
|
|
115
|
+
CONTEXT_URL_MAP.w3c.did.v1,
|
|
116
|
+
CONTEXT_URL_MAP.w3c.multikey.v1
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
export const BTC1_DID_UPDATE_PAYLOAD_CONTEXT = [
|
|
120
|
+
CONTEXT_URL_MAP.w3c.security.v2,
|
|
121
|
+
CONTEXT_URL_MAP.w3c.zcap.v1,
|
|
122
|
+
CONTEXT_URL_MAP.w3c.jsonldpatch.v1,
|
|
123
|
+
];
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An enumeration of possible DID error codes.
|
|
3
|
+
*/
|
|
4
|
+
export enum Btc1ErrorCode {
|
|
5
|
+
/** The DID supplied does not conform to valid syntax. */
|
|
6
|
+
INVALID_DID = 'INVALID_DID',
|
|
7
|
+
|
|
8
|
+
/** The supplied method name is not supported by the DID method and/or DID resolver implementation. */
|
|
9
|
+
METHOD_NOT_SUPPORTED = 'METHOD_NOT_SUPPORTED',
|
|
10
|
+
|
|
11
|
+
/** An unexpected error occurred during the requested DID operation. */
|
|
12
|
+
INTERNAL_ERROR = 'INTERNAL_ERROR',
|
|
13
|
+
|
|
14
|
+
/** The DID document supplied does not conform to valid syntax. */
|
|
15
|
+
INVALID_DID_DOCUMENT = 'INVALID_DID_DOCUMENT',
|
|
16
|
+
|
|
17
|
+
/** The DID Update supplied does not conform to valid syntax. */
|
|
18
|
+
INVALID_DID_UPDATE = 'INVALID_DID_UPDATE',
|
|
19
|
+
|
|
20
|
+
/** The byte length of a DID document does not match the expected value. */
|
|
21
|
+
INVALID_DID_DOCUMENT_LENGTH = 'INVALID_DID_DOCUMENT_LENGTH',
|
|
22
|
+
|
|
23
|
+
/** The DID URL supplied to the dereferencing function does not conform to valid syntax. */
|
|
24
|
+
INVALID_DID_URL = 'INVALID_DID_URL',
|
|
25
|
+
|
|
26
|
+
/** The given proof of a previous DID is invalid */
|
|
27
|
+
INVALID_PREVIOUS_DID_PROOF = 'INVALID_PREVIOUS_DID_PROOF',
|
|
28
|
+
|
|
29
|
+
/** An invalid public key is detected during a DID operation. */
|
|
30
|
+
INVALID_PUBLIC_KEY = 'INVALID_PUBLIC_KEY',
|
|
31
|
+
|
|
32
|
+
/** An invalid multibase format is detected on the public key during a DID operation. */
|
|
33
|
+
INVALID_PUBLIC_KEY_MULTIBASE = 'INVALID_PUBLIC_KEY_MULTIBASE',
|
|
34
|
+
|
|
35
|
+
/** The byte length of a public key does not match the expected value. */
|
|
36
|
+
INVALID_PUBLIC_KEY_LENGTH = 'INVALID_PUBLIC_KEY_LENGTH',
|
|
37
|
+
|
|
38
|
+
/** An invalid public key type was detected during a DID operation. */
|
|
39
|
+
INVALID_PUBLIC_KEY_TYPE = 'INVALID_PUBLIC_KEY_TYPE',
|
|
40
|
+
|
|
41
|
+
/** Verification of a signature failed during a DID operation. */
|
|
42
|
+
INVALID_SIGNATURE = 'INVALID_SIGNATURE',
|
|
43
|
+
|
|
44
|
+
/** General: The resource requested was not found. */
|
|
45
|
+
/** DID Resolution: The DID resolver was unable to find the DID document resulting from the resolution request. */
|
|
46
|
+
NOT_FOUND = 'NOT_FOUND',
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The representation requested via the `accept` input metadata property is not supported by the
|
|
50
|
+
* DID method and/or DID resolver implementation.
|
|
51
|
+
*/
|
|
52
|
+
REPRESENTATION_NOT_SUPPORTED = 'REPRESENTATION_NOT_SUPPORTED',
|
|
53
|
+
|
|
54
|
+
/** The type of a public key is not supported by the DID method and/or DID resolver implementation. */
|
|
55
|
+
UNSUPPORTED_PUBLIC_KEY_TYPE = 'UNSUPPORTED_PUBLIC_KEY_TYPE',
|
|
56
|
+
|
|
57
|
+
/** The proof verification operation failed. */
|
|
58
|
+
PROOF_VERIFICATION_ERROR = 'PROOF_VERIFICATION_ERROR',
|
|
59
|
+
|
|
60
|
+
/** The proof generation operation failed. */
|
|
61
|
+
PROOF_GENERATION_ERROR = 'PROOF_GENERATION_ERROR',
|
|
62
|
+
|
|
63
|
+
/** The proof serialization operation failed. */
|
|
64
|
+
PROOF_SERIALIZATION_ERROR = 'PROOF_SERIALIZATION_ERROR',
|
|
65
|
+
|
|
66
|
+
/** The proof could not be parsed properly. */
|
|
67
|
+
PROOF_PARSING_ERROR = 'PROOF_PARSING_ERROR',
|
|
68
|
+
|
|
69
|
+
/** The verification method was formed improperly. */
|
|
70
|
+
VERIFICATION_METHOD_ERROR = 'VERIFICATION_METHOD_ERROR',
|
|
71
|
+
|
|
72
|
+
/** Something about the DID Update Payload indicates the potential for late publishing. */
|
|
73
|
+
LATE_PUBLISHING_ERROR = 'LATE_PUBLISHING_ERROR',
|
|
74
|
+
|
|
75
|
+
/** The sidecar data in the DID Update Payload was invalid. */
|
|
76
|
+
INVALID_SIDECAR_DATA = 'INVALID_SIDECAR_DATA',
|
|
77
|
+
|
|
78
|
+
/** The proof is missing or has a malformed challenge field. */
|
|
79
|
+
INVALID_CHALLENGE_ERROR = 'INVALID_CHALLENGE_ERROR',
|
|
80
|
+
|
|
81
|
+
/** The proof is missing or has a malformed domain field. */
|
|
82
|
+
INVALID_DOMAIN_ERROR = 'INVALID_DOMAIN_ERROR'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const {
|
|
86
|
+
INVALID_DID,
|
|
87
|
+
METHOD_NOT_SUPPORTED,
|
|
88
|
+
INTERNAL_ERROR,
|
|
89
|
+
INVALID_DID_DOCUMENT,
|
|
90
|
+
INVALID_DID_UPDATE,
|
|
91
|
+
INVALID_DID_DOCUMENT_LENGTH,
|
|
92
|
+
INVALID_DID_URL,
|
|
93
|
+
INVALID_PREVIOUS_DID_PROOF,
|
|
94
|
+
INVALID_PUBLIC_KEY,
|
|
95
|
+
INVALID_PUBLIC_KEY_MULTIBASE,
|
|
96
|
+
INVALID_PUBLIC_KEY_LENGTH,
|
|
97
|
+
INVALID_PUBLIC_KEY_TYPE,
|
|
98
|
+
INVALID_SIGNATURE,
|
|
99
|
+
NOT_FOUND,
|
|
100
|
+
REPRESENTATION_NOT_SUPPORTED,
|
|
101
|
+
UNSUPPORTED_PUBLIC_KEY_TYPE,
|
|
102
|
+
PROOF_VERIFICATION_ERROR,
|
|
103
|
+
PROOF_GENERATION_ERROR,
|
|
104
|
+
PROOF_SERIALIZATION_ERROR,
|
|
105
|
+
PROOF_PARSING_ERROR,
|
|
106
|
+
VERIFICATION_METHOD_ERROR,
|
|
107
|
+
LATE_PUBLISHING_ERROR,
|
|
108
|
+
INVALID_SIDECAR_DATA,
|
|
109
|
+
INVALID_CHALLENGE_ERROR,
|
|
110
|
+
INVALID_DOMAIN_ERROR
|
|
111
|
+
} = Btc1ErrorCode;
|
|
112
|
+
|
|
113
|
+
export type ErrorOptions = {
|
|
114
|
+
type?: string;
|
|
115
|
+
name?: string;
|
|
116
|
+
data?: any;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export class DidBtc1Error extends Error {
|
|
120
|
+
name: string = 'DidBtc1Error';
|
|
121
|
+
type: string = 'DidBtc1Error';
|
|
122
|
+
data?: Record<string, any>;
|
|
123
|
+
|
|
124
|
+
constructor(message: string, options: ErrorOptions = {}) {
|
|
125
|
+
super(message);
|
|
126
|
+
this.type = options.type ?? this.type;
|
|
127
|
+
this.name = options.name ?? this.name;
|
|
128
|
+
this.data = options.data;
|
|
129
|
+
|
|
130
|
+
// Ensures that instanceof works properly, the correct prototype chain when using inheritance,
|
|
131
|
+
// and that V8 stack traces (like Chrome, Edge, and Node.js) are more readable and relevant.
|
|
132
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
133
|
+
|
|
134
|
+
// Captures the stack trace in V8 engines (like Chrome, Edge, and Node.js).
|
|
135
|
+
// In non-V8 environments, the stack trace will still be captured.
|
|
136
|
+
if (Error.captureStackTrace) {
|
|
137
|
+
Error.captureStackTrace(this, DidBtc1Error);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export class Btc1Error extends DidBtc1Error {
|
|
143
|
+
constructor(message: string, type: string, data?: Record<string, any>) {
|
|
144
|
+
super(message, { type, name: type, data });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export class Btc1ReadError extends DidBtc1Error {
|
|
149
|
+
constructor(message: string, type: string = 'Btc1ReadError', data?: Record<string, any>) {
|
|
150
|
+
super(message, { type, name: 'Btc1ReadError', data });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export class Btc1KeyManagerError extends DidBtc1Error {
|
|
155
|
+
constructor(message: string, type: string = 'Btc1KeyManagerError', data?: Record<string, any>) {
|
|
156
|
+
super(message, { type, name: type, data });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export class DidDocumentError extends DidBtc1Error {
|
|
161
|
+
constructor(message: string, type: string = 'DidDocumentError', data?: Record<string, any>) {
|
|
162
|
+
super(message, { type, name: type, data });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export class CryptosuiteError extends DidBtc1Error {
|
|
167
|
+
constructor(message: string, type: string = 'CryptosuiteError', data?: Record<string, any>) {
|
|
168
|
+
super(message, { type, name: type, data });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export class KeyPairError extends DidBtc1Error {
|
|
173
|
+
constructor(message: string, type: string = 'KeyPairError', data?: Record<string, any>) {
|
|
174
|
+
super(message, { type, name: type, data });
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export class SecretKeyError extends DidBtc1Error {
|
|
179
|
+
constructor(message: string, type: string = 'SecretKeyError', data?: Record<string, any>) {
|
|
180
|
+
super(message, { type, name: type, data });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export class PublicKeyError extends DidBtc1Error {
|
|
185
|
+
constructor(message: string, type: string = 'PublicKeyError', data?: Record<string, any>) {
|
|
186
|
+
super(message, { type, name: type, data });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export class MultikeyError extends DidBtc1Error {
|
|
191
|
+
constructor(message: string, type: string = 'MultikeyError', data?: Record<string, any>) {
|
|
192
|
+
super(message, { type, name: type, data });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export class ProofError extends DidBtc1Error {
|
|
197
|
+
constructor(message: string, type: string = 'ProofError', data?: Record<string, any>) {
|
|
198
|
+
super(message, { type, name: type, data });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export class SingletonBeaconError extends DidBtc1Error {
|
|
203
|
+
constructor(message: string, type: string = 'SingletonBeaconError', data?: Record<string, any>) {
|
|
204
|
+
super(message, { type, name: type, data });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export class CIDAggregateBeaconError extends DidBtc1Error {
|
|
209
|
+
constructor(message: string, type: string = 'CIDAggregateBeaconError', data?: Record<string, any>) {
|
|
210
|
+
super(message, { type, name: type, data });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export class SMTAggregateBeaconError extends DidBtc1Error {
|
|
215
|
+
constructor(message: string, type: string = 'SMTAggregateBeaconError', data?: Record<string, any>) {
|
|
216
|
+
super(message, { type, name: type, data });
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export class CanonicalizationError extends DidBtc1Error {
|
|
221
|
+
constructor(message: string, type: string = 'CanonicalizationError', data?: Record<string, any>) {
|
|
222
|
+
super(message, { type, name: type, data });
|
|
223
|
+
}
|
|
224
|
+
}
|