@did-btcr2/method 0.60.0 → 0.62.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/README.md +4 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.js +3 -3
- package/dist/browser.mjs +3 -3
- package/dist/cjs/index.js +56 -18
- package/dist/esm/core/btcr2-update.js +28 -1
- package/dist/esm/core/btcr2-update.js.map +1 -1
- package/dist/esm/core/identifier.js +12 -2
- package/dist/esm/core/identifier.js.map +1 -1
- package/dist/esm/core/resolver.js +22 -7
- package/dist/esm/core/resolver.js.map +1 -1
- package/dist/esm/core/updater.js +8 -12
- package/dist/esm/core/updater.js.map +1 -1
- package/dist/esm/utils/appendix.js +2 -1
- package/dist/esm/utils/appendix.js.map +1 -1
- package/dist/types/core/btcr2-update.d.ts +22 -3
- package/dist/types/core/btcr2-update.d.ts.map +1 -1
- package/dist/types/core/identifier.d.ts.map +1 -1
- package/dist/types/core/resolver.d.ts +18 -5
- package/dist/types/core/resolver.d.ts.map +1 -1
- package/dist/types/core/updater.d.ts.map +1 -1
- package/dist/types/utils/appendix.d.ts +2 -1
- package/dist/types/utils/appendix.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/core/btcr2-update.ts +36 -3
- package/src/core/identifier.ts +14 -2
- package/src/core/resolver.ts +46 -12
- package/src/core/updater.ts +8 -12
- package/src/utils/appendix.ts +2 -1
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import type { PatchOperation } from '@did-btcr2/common';
|
|
2
2
|
import type { DataIntegrityProofObject, DataIntegrityProofOptions } from '@did-btcr2/cryptosuite';
|
|
3
|
+
/**
|
|
4
|
+
* The `@context` array of a BTCR2 Update. The specification pins the members and their
|
|
5
|
+
* order. The array is part of the bytes that the JSON Document Hashing algorithm hashes
|
|
6
|
+
* and that the proof signs, so an update with a different array is a different update,
|
|
7
|
+
* and a conformant resolver rejects it. The proof of a signed update carries the same
|
|
8
|
+
* array. See
|
|
9
|
+
* {@link https://dcdpr.github.io/did-btcr2/data-structures.html#btcr2-unsigned-update | BTCR2 Unsigned Update (data structure)}.
|
|
10
|
+
*/
|
|
11
|
+
export declare const BTCR2_UPDATE_CONTEXT: readonly ["https://w3id.org/json-ld-patch/v1", "https://w3id.org/zcap/v1", "https://w3id.org/security/data-integrity/v2", "https://btcr2.dev/context/v1"];
|
|
12
|
+
/**
|
|
13
|
+
* True if `value` is an array with the same context URLs as `expected`, in the same
|
|
14
|
+
* order, and with no other member. This is the equality rule of the specification for
|
|
15
|
+
* two `@context` arrays. `expected` defaults to {@link BTCR2_UPDATE_CONTEXT}.
|
|
16
|
+
*
|
|
17
|
+
* @param {unknown} value The `@context` value to check.
|
|
18
|
+
* @param {readonly string[]} expected The array that `value` must equal.
|
|
19
|
+
* @returns {boolean} True if the two arrays are equal.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isBtcr2UpdateContext(value: unknown, expected?: readonly string[]): value is string[];
|
|
3
22
|
/**
|
|
4
23
|
* A {@link https://dcdpr.github.io/did-btcr2/terminology.html#btcr2-update | BTCR2 Update} without a data integrity proof.
|
|
5
24
|
* See {@link https://dcdpr.github.io/did-btcr2/data-structures.html#btcr2-unsigned-update | BTCR2 Unsigned Update (data structure)}.
|
|
@@ -11,8 +30,8 @@ import type { DataIntegrityProofObject, DataIntegrityProofOptions } from '@did-b
|
|
|
11
30
|
*/
|
|
12
31
|
export type UnsignedBTCR2Update = {
|
|
13
32
|
/**
|
|
14
|
-
* JSON-LD context
|
|
15
|
-
*
|
|
33
|
+
* The JSON-LD context array of the update: exactly the members of
|
|
34
|
+
* {@link BTCR2_UPDATE_CONTEXT}, in that order.
|
|
16
35
|
*/
|
|
17
36
|
'@context': string[];
|
|
18
37
|
/**
|
|
@@ -66,7 +85,7 @@ export type BTCR2Update = UnsignedBTCR2Update | SignedBTCR2Update;
|
|
|
66
85
|
* {@link https://dcdpr.github.io/did-btcr2/data-structures.html#data-integrity-config | Data Integrity Config}.
|
|
67
86
|
*/
|
|
68
87
|
export type Btcr2DataIntegrityConfig = DataIntegrityProofOptions & {
|
|
69
|
-
/**
|
|
88
|
+
/** The same array as the update `@context`: {@link BTCR2_UPDATE_CONTEXT}. */
|
|
70
89
|
'@context': string[];
|
|
71
90
|
/** The root capability being invoked, e.g. `urn:zcap:root:<urlencoded-did>`. */
|
|
72
91
|
capability?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"btcr2-update.d.ts","sourceRoot":"","sources":["../../../src/core/btcr2-update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAElG;;;;;;;;GAQG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;OAGG;IACH,UAAU,EAAE,MAAM,EAAE,CAAC;IAErB;;;;OAIG;IACH,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IAE7B;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,wBAAwB,GAAG;IAC/D,gFAAgF;IAChF,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,4FAA4F;IAC5F,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,mBAAmB,GAAG;IACpD,sFAAsF;IACtF,KAAK,EAAE,uBAAuB,CAAC;CAChC,CAAC;AAEF,qCAAqC;AACrC,MAAM,MAAM,WAAW,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;AAElE;;;;;GAKG;AACH,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,GAAG;IACjE,
|
|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
* The response object for DID Resolution.
|
|
17
|
+
* The response object for DID Resolution. `metadata` is the DID document metadata
|
|
18
|
+
* of the specification: `versionId`, `confirmations`, and `deactivated` are always
|
|
19
|
+
* present; `updated` is present after the resolver applies an update.
|
|
18
20
|
*/
|
|
19
21
|
export interface DidResolutionResponse {
|
|
20
22
|
didDocument: DidDocument;
|
|
21
23
|
metadata: {
|
|
22
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Number of confirmations of the Bitcoin block that contains the last applied
|
|
26
|
+
* unique update. `0` when the resolver applied no update.
|
|
27
|
+
*/
|
|
28
|
+
confirmations: number;
|
|
29
|
+
/** The version of the resolved document as an ASCII string. `"1"` when the resolver applied no update. */
|
|
23
30
|
versionId: string;
|
|
31
|
+
/**
|
|
32
|
+
* XML Datetime (UTC, no fraction) of the block of the last applied update.
|
|
33
|
+
* Absent until the resolver applies an update.
|
|
34
|
+
*/
|
|
24
35
|
updated?: string;
|
|
25
|
-
deactivated
|
|
36
|
+
/** Whether the resolved document is deactivated. */
|
|
37
|
+
deactivated: boolean;
|
|
26
38
|
};
|
|
27
39
|
}
|
|
28
40
|
/** The resolver needs a genesis document whose hash matches genesisHash. */
|
|
@@ -128,7 +140,7 @@ export declare class Resolver {
|
|
|
128
140
|
* @param {DidComponents} didComponents BTCR2 DID components used to resolve the DID Document
|
|
129
141
|
* @param {object} genesisDocument The genesis document for resolving the DID Document.
|
|
130
142
|
* @returns {DidDocument} The resolved DID Document object
|
|
131
|
-
* @throws {ResolveError}
|
|
143
|
+
* @throws {ResolveError} `INVALID_DID` if the hash of the genesis document is not the genesis bytes of the identifier
|
|
132
144
|
*/
|
|
133
145
|
static external(didComponents: DidComponents, genesisDocument: object): DidDocument;
|
|
134
146
|
/**
|
|
@@ -165,7 +177,8 @@ export declare class Resolver {
|
|
|
165
177
|
*/
|
|
166
178
|
private static confirmDuplicate;
|
|
167
179
|
/**
|
|
168
|
-
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#apply-update | 7.2.f.3 Apply Update}
|
|
180
|
+
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#apply-update | 7.2.f.3 Apply Update}
|
|
181
|
+
* and its step {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#check-update-proof | Check update.proof}.
|
|
169
182
|
* @param {DidDocument} currentDocument The current DID Document to apply the update to.
|
|
170
183
|
* @param {SignedBTCR2Update} update The BTCR2 Signed Update to apply.
|
|
171
184
|
* @returns {DidDocument} The updated DID Document after applying the update.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../src/core/resolver.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EACV,iBAAiB,EAElB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../src/core/resolver.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EACV,iBAAiB,EAElB,MAAM,mBAAmB,CAAC;AAU3B,OAAO,EAAE,WAAW,EAAwB,MAAM,0BAA0B,CAAC;AAE7E,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEzF,OAAO,KAAK,EAAE,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAEpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGxE;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,EAAE;QACR;;;WAGG;QACH,aA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M,EAClB,eAAe,GAAE;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,iBAAiB,EAAE,SAAS,EAAE,CAAA;KAC7B,GAC7C,qBAAqB;IA+HxB;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IA+C/B;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IA8H1B;;;;;;OAMG;IACH,OAAO,IAAI,aAAa;IA2MxB;;;;;;;;OAQG;IACH,OAAO,CAAC,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IACtD,OAAO,CAAC,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,GAAG,IAAI;IACrF,OAAO,CAAC,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,eAAe,GAAG,IAAI;IAC/D,OAAO,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,iBAAiB,GAAG,IAAI;IAC9D,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,GAAG,IAAI;CAuFlD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updater.d.ts","sourceRoot":"","sources":["../../../src/core/updater.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAA4B,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"updater.d.ts","sourceRoot":"","sources":["../../../src/core/updater.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,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B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,eAAe,CAAC;IAa3B;;;;OAIG;IACH,OAAO,IAAI,YAAY;IAkEvB;;;;;;OAMG;IACH,OAAO,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IACjD,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,YAAY,GAAG,IAAI;IACtD,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI;CAkEnC"}
|
|
@@ -93,9 +93,10 @@ export declare class Appendix {
|
|
|
93
93
|
* ```
|
|
94
94
|
* {
|
|
95
95
|
* "@context": [
|
|
96
|
+
* "https://w3id.org/json-ld-patch/v1",
|
|
96
97
|
* "https://w3id.org/zcap/v1",
|
|
97
98
|
* "https://w3id.org/security/data-integrity/v2",
|
|
98
|
-
* "https://
|
|
99
|
+
* "https://btcr2.dev/context/v1"
|
|
99
100
|
* ],
|
|
100
101
|
* "patch": [
|
|
101
102
|
* {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appendix.d.ts","sourceRoot":"","sources":["../../../src/utils/appendix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,qBAAqB,EAAC,MAAM,YAAY,CAAC;AAO3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;;GAKG;AACH,qBAAa,QAAQ;IACnB;;;;;;;;;;;OAWG;WACW,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAM7E;;;;;;;;;;;;;;;;;OAiBG;WACW,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAOnF;;;;OAIG;WACW,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,qBAAqB;IAcjF;;;;OA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
{
|
|
2
2
|
"name": "@did-btcr2/method",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.62.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Reference implementation for the did:btcr2 DID method written in TypeScript and JavaScript. did:btcr2 is a censorship resistant DID Method using the Bitcoin blockchain as a Verifiable Data Registry to announce changes to the DID document. This is the core method implementation for the did-btcr2-js monorepo.",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
"@scure/btc-signer": "^1.8.1",
|
|
71
71
|
"@web5/dids": "^1.2.0",
|
|
72
72
|
"@did-btcr2/bitcoin": "^0.11.0",
|
|
73
|
+
"@did-btcr2/common": "^9.5.0",
|
|
73
74
|
"@did-btcr2/smt": "^0.3.0",
|
|
74
|
-
"@did-btcr2/cryptosuite": "^10.0.0",
|
|
75
75
|
"@did-btcr2/keypair": "^0.13.1",
|
|
76
|
-
"@did-btcr2/
|
|
76
|
+
"@did-btcr2/cryptosuite": "^10.0.0"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@eslint/js": "^9.39.4",
|
package/src/core/btcr2-update.ts
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
import type { PatchOperation } from '@did-btcr2/common';
|
|
2
2
|
import type { DataIntegrityProofObject, DataIntegrityProofOptions } from '@did-btcr2/cryptosuite';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The `@context` array of a BTCR2 Update. The specification pins the members and their
|
|
6
|
+
* order. The array is part of the bytes that the JSON Document Hashing algorithm hashes
|
|
7
|
+
* and that the proof signs, so an update with a different array is a different update,
|
|
8
|
+
* and a conformant resolver rejects it. The proof of a signed update carries the same
|
|
9
|
+
* array. See
|
|
10
|
+
* {@link https://dcdpr.github.io/did-btcr2/data-structures.html#btcr2-unsigned-update | BTCR2 Unsigned Update (data structure)}.
|
|
11
|
+
*/
|
|
12
|
+
export const BTCR2_UPDATE_CONTEXT = Object.freeze([
|
|
13
|
+
'https://w3id.org/json-ld-patch/v1',
|
|
14
|
+
'https://w3id.org/zcap/v1',
|
|
15
|
+
'https://w3id.org/security/data-integrity/v2',
|
|
16
|
+
'https://btcr2.dev/context/v1',
|
|
17
|
+
] as const);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* True if `value` is an array with the same context URLs as `expected`, in the same
|
|
21
|
+
* order, and with no other member. This is the equality rule of the specification for
|
|
22
|
+
* two `@context` arrays. `expected` defaults to {@link BTCR2_UPDATE_CONTEXT}.
|
|
23
|
+
*
|
|
24
|
+
* @param {unknown} value The `@context` value to check.
|
|
25
|
+
* @param {readonly string[]} expected The array that `value` must equal.
|
|
26
|
+
* @returns {boolean} True if the two arrays are equal.
|
|
27
|
+
*/
|
|
28
|
+
export function isBtcr2UpdateContext(
|
|
29
|
+
value: unknown,
|
|
30
|
+
expected: readonly string[] = BTCR2_UPDATE_CONTEXT
|
|
31
|
+
): value is string[] {
|
|
32
|
+
return Array.isArray(value)
|
|
33
|
+
&& value.length === expected.length
|
|
34
|
+
&& value.every((url, i) => url === expected[i]);
|
|
35
|
+
}
|
|
36
|
+
|
|
4
37
|
/**
|
|
5
38
|
* A {@link https://dcdpr.github.io/did-btcr2/terminology.html#btcr2-update | BTCR2 Update} without a data integrity proof.
|
|
6
39
|
* See {@link https://dcdpr.github.io/did-btcr2/data-structures.html#btcr2-unsigned-update | BTCR2 Unsigned Update (data structure)}.
|
|
@@ -12,8 +45,8 @@ import type { DataIntegrityProofObject, DataIntegrityProofOptions } from '@did-b
|
|
|
12
45
|
*/
|
|
13
46
|
export type UnsignedBTCR2Update = {
|
|
14
47
|
/**
|
|
15
|
-
* JSON-LD context
|
|
16
|
-
*
|
|
48
|
+
* The JSON-LD context array of the update: exactly the members of
|
|
49
|
+
* {@link BTCR2_UPDATE_CONTEXT}, in that order.
|
|
17
50
|
*/
|
|
18
51
|
'@context': string[];
|
|
19
52
|
|
|
@@ -76,7 +109,7 @@ export type BTCR2Update = UnsignedBTCR2Update | SignedBTCR2Update;
|
|
|
76
109
|
* {@link https://dcdpr.github.io/did-btcr2/data-structures.html#data-integrity-config | Data Integrity Config}.
|
|
77
110
|
*/
|
|
78
111
|
export type Btcr2DataIntegrityConfig = DataIntegrityProofOptions & {
|
|
79
|
-
/**
|
|
112
|
+
/** The same array as the update `@context`: {@link BTCR2_UPDATE_CONTEXT}. */
|
|
80
113
|
'@context': string[];
|
|
81
114
|
|
|
82
115
|
/** The root capability being invoked, e.g. `urn:zcap:root:<urlencoded-did>`. */
|
package/src/core/identifier.ts
CHANGED
|
@@ -223,8 +223,20 @@ export class Identifier {
|
|
|
223
223
|
throw new IdentifierError(`Invalid method-specific id (must be lowercase): ${identifier}`, INVALID_DID, { identifier });
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
// 7. Bech32m-decode the id into its hrp and dataBytes.
|
|
227
|
-
|
|
226
|
+
// 7. Bech32m-decode the id into its hrp and dataBytes. The decoder throws its own Error
|
|
227
|
+
// for a bad character, a bad length, a bad checksum, or bad padding. The specification
|
|
228
|
+
// maps every decoding failure to INVALID_DID.
|
|
229
|
+
let hrp: string;
|
|
230
|
+
let dataBytes: Uint8Array;
|
|
231
|
+
try {
|
|
232
|
+
({ prefix: hrp, bytes: dataBytes } = bech32m.decodeToBytes(encoded));
|
|
233
|
+
} catch (error: unknown) {
|
|
234
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
235
|
+
throw new IdentifierError(
|
|
236
|
+
`Invalid method-specific id (Bech32m decoding failed: ${reason}): ${identifier}`,
|
|
237
|
+
INVALID_DID, { identifier, reason }
|
|
238
|
+
);
|
|
239
|
+
}
|
|
228
240
|
|
|
229
241
|
// 8. The hrp MUST be "k" (KEY) or "x" (EXTERNAL).
|
|
230
242
|
if (!['x', 'k'].includes(hrp)) {
|
package/src/core/resolver.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
encode as encodeHash,
|
|
8
8
|
decode as decodeHash,
|
|
9
9
|
INTERNAL_ERROR,
|
|
10
|
-
|
|
10
|
+
INVALID_DID,
|
|
11
11
|
INVALID_DID_UPDATE,
|
|
12
12
|
INVALID_OPTIONS,
|
|
13
13
|
JSONPatch,
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
SignedBTCR2Update,
|
|
21
21
|
UnsignedBTCR2Update
|
|
22
22
|
} from './btcr2-update.js';
|
|
23
|
+
import { BTCR2_UPDATE_CONTEXT, isBtcr2UpdateContext } from './btcr2-update.js';
|
|
23
24
|
import {
|
|
24
25
|
BIP340Cryptosuite,
|
|
25
26
|
BIP340DataIntegrityProof,
|
|
@@ -48,15 +49,27 @@ import { equalBytes } from '@noble/curves/utils.js';
|
|
|
48
49
|
export const DEFAULT_MIN_CONF = 6;
|
|
49
50
|
|
|
50
51
|
/**
|
|
51
|
-
* The response object for DID Resolution.
|
|
52
|
+
* The response object for DID Resolution. `metadata` is the DID document metadata
|
|
53
|
+
* of the specification: `versionId`, `confirmations`, and `deactivated` are always
|
|
54
|
+
* present; `updated` is present after the resolver applies an update.
|
|
52
55
|
*/
|
|
53
56
|
export interface DidResolutionResponse {
|
|
54
57
|
didDocument: DidDocument;
|
|
55
58
|
metadata: {
|
|
56
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Number of confirmations of the Bitcoin block that contains the last applied
|
|
61
|
+
* unique update. `0` when the resolver applied no update.
|
|
62
|
+
*/
|
|
63
|
+
confirmations: number;
|
|
64
|
+
/** The version of the resolved document as an ASCII string. `"1"` when the resolver applied no update. */
|
|
57
65
|
versionId: string;
|
|
66
|
+
/**
|
|
67
|
+
* XML Datetime (UTC, no fraction) of the block of the last applied update.
|
|
68
|
+
* Absent until the resolver applies an update.
|
|
69
|
+
*/
|
|
58
70
|
updated?: string;
|
|
59
|
-
deactivated
|
|
71
|
+
/** Whether the resolved document is deactivated. */
|
|
72
|
+
deactivated: boolean;
|
|
60
73
|
}
|
|
61
74
|
}
|
|
62
75
|
|
|
@@ -340,7 +353,7 @@ export class Resolver {
|
|
|
340
353
|
* @param {DidComponents} didComponents BTCR2 DID components used to resolve the DID Document
|
|
341
354
|
* @param {object} genesisDocument The genesis document for resolving the DID Document.
|
|
342
355
|
* @returns {DidDocument} The resolved DID Document object
|
|
343
|
-
* @throws {ResolveError}
|
|
356
|
+
* @throws {ResolveError} `INVALID_DID` if the hash of the genesis document is not the genesis bytes of the identifier
|
|
344
357
|
*/
|
|
345
358
|
static external(
|
|
346
359
|
didComponents: DidComponents,
|
|
@@ -349,11 +362,12 @@ export class Resolver {
|
|
|
349
362
|
// Canonicalize and sha256 hash the genesis document
|
|
350
363
|
const genesisDocumentHash = canonicalHashBytes(genesisDocument);
|
|
351
364
|
|
|
352
|
-
// Compare genesis bytes from identifier against the document hash (byte comparison)
|
|
365
|
+
// Compare genesis bytes from identifier against the document hash (byte comparison).
|
|
366
|
+
// The specification raises INVALID_DID when the computed hash does not match genesis_bytes.
|
|
353
367
|
if (!equalBytes(didComponents.genesisBytes, genesisDocumentHash)) {
|
|
354
368
|
throw new ResolveError(
|
|
355
369
|
`Initial document mismatch: genesisBytes !== genesisDocumentHash`,
|
|
356
|
-
|
|
370
|
+
INVALID_DID, {
|
|
357
371
|
genesisBytes : encodeHash(didComponents.genesisBytes, 'hex'),
|
|
358
372
|
genesisDocumentHash : encodeHash(genesisDocumentHash, 'hex')
|
|
359
373
|
}
|
|
@@ -438,13 +452,12 @@ export class Resolver {
|
|
|
438
452
|
upd0.targetVersionId - upd1.targetVersionId || blk0.height - blk1.height
|
|
439
453
|
);
|
|
440
454
|
|
|
441
|
-
// Create a default response object
|
|
455
|
+
// Create a default response object. `updated` is absent until an update applies.
|
|
442
456
|
const response: DidResolutionResponse = {
|
|
443
457
|
didDocument : currentDocument,
|
|
444
458
|
metadata : {
|
|
445
459
|
versionId : `${currentVersionId}`,
|
|
446
460
|
confirmations : 0,
|
|
447
|
-
updated : '',
|
|
448
461
|
deactivated : currentDocument.deactivated || false
|
|
449
462
|
}
|
|
450
463
|
};
|
|
@@ -608,7 +621,8 @@ export class Resolver {
|
|
|
608
621
|
}
|
|
609
622
|
|
|
610
623
|
/**
|
|
611
|
-
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#apply-update | 7.2.f.3 Apply Update}
|
|
624
|
+
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#apply-update | 7.2.f.3 Apply Update}
|
|
625
|
+
* and its step {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#check-update-proof | Check update.proof}.
|
|
612
626
|
* @param {DidDocument} currentDocument The current DID Document to apply the update to.
|
|
613
627
|
* @param {SignedBTCR2Update} update The BTCR2 Signed Update to apply.
|
|
614
628
|
* @returns {DidDocument} The updated DID Document after applying the update.
|
|
@@ -618,6 +632,24 @@ export class Resolver {
|
|
|
618
632
|
currentDocument: DidDocument,
|
|
619
633
|
update: SignedBTCR2Update
|
|
620
634
|
): DidDocument {
|
|
635
|
+
// Spec "Check update.proof": the update @context must be the array that the BTCR2
|
|
636
|
+
// Unsigned Update data structure pins, and the proof @context must equal it, member
|
|
637
|
+
// for member and in order. The array is inside the hashed and signed bytes, so an
|
|
638
|
+
// update with another array is a different update. The check runs before signature
|
|
639
|
+
// verification so that the failure names the array and not the signature.
|
|
640
|
+
if(!isBtcr2UpdateContext(update['@context'])) {
|
|
641
|
+
throw new ResolveError(
|
|
642
|
+
'Invalid update: @context is not the array the specification pins for a BTCR2 Update',
|
|
643
|
+
INVALID_DID_UPDATE, { context: update['@context'], expected: [ ...BTCR2_UPDATE_CONTEXT ] }
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
if(!isBtcr2UpdateContext(update.proof?.['@context'], update['@context'])) {
|
|
647
|
+
throw new ResolveError(
|
|
648
|
+
'Invalid update: proof @context does not equal the update @context',
|
|
649
|
+
INVALID_DID_UPDATE, { proofContext: update.proof?.['@context'], context: update['@context'] }
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
|
|
621
653
|
// Get the capability id from the to update proof.
|
|
622
654
|
const capabilityId = update.proof?.capability;
|
|
623
655
|
// Since this field is optional, check that it exists
|
|
@@ -880,11 +912,13 @@ export class Resolver {
|
|
|
880
912
|
case ResolverPhase.Complete: {
|
|
881
913
|
return {
|
|
882
914
|
status : 'resolved',
|
|
915
|
+
// No update applied: confirmations is 0 per the specification.
|
|
883
916
|
result : this.#resolvedResponse ?? {
|
|
884
917
|
didDocument : this.#currentDocument!,
|
|
885
918
|
metadata : {
|
|
886
|
-
versionId
|
|
887
|
-
|
|
919
|
+
versionId : this.#versionId ?? '1',
|
|
920
|
+
confirmations : 0,
|
|
921
|
+
deactivated : this.#currentDocument!.deactivated || false
|
|
888
922
|
}
|
|
889
923
|
}
|
|
890
924
|
};
|
package/src/core/updater.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { canonicalHash, INVALID_DID_UPDATE, JSONPatch, UpdateError } from '@did-
|
|
|
4
4
|
import { SchnorrMultikey } from '@did-btcr2/cryptosuite';
|
|
5
5
|
import type { Signer } from '@did-btcr2/keypair';
|
|
6
6
|
import type { Btcr2DataIntegrityConfig, SignedBTCR2Update, UnsignedBTCR2Update } from './btcr2-update.js';
|
|
7
|
+
import { BTCR2_UPDATE_CONTEXT } from './btcr2-update.js';
|
|
7
8
|
import { DidDocument, type Btcr2DidDocument, type DidVerificationMethod } from '../utils/did-document.js';
|
|
8
9
|
import type { BroadcastResult } from './beacon/beacon.js';
|
|
9
10
|
import type { CASBroadcastOptions } from './beacon/cas-beacon.js';
|
|
@@ -214,12 +215,9 @@ export class Updater {
|
|
|
214
215
|
sourceVersionId: number,
|
|
215
216
|
): UnsignedBTCR2Update {
|
|
216
217
|
const unsignedUpdate: UnsignedBTCR2Update = {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
'https://w3id.org/json-ld-patch/v1',
|
|
221
|
-
'https://btcr2.dev/context/v1'
|
|
222
|
-
],
|
|
218
|
+
// The array the specification pins, as a fresh copy: the update is a plain JSON
|
|
219
|
+
// object that callers may edit, and the shared constant is frozen.
|
|
220
|
+
'@context' : [ ...BTCR2_UPDATE_CONTEXT ],
|
|
223
221
|
patch : patches,
|
|
224
222
|
targetHash : '',
|
|
225
223
|
targetVersionId : sourceVersionId + 1,
|
|
@@ -311,12 +309,10 @@ export class Updater {
|
|
|
311
309
|
}
|
|
312
310
|
|
|
313
311
|
const config: Btcr2DataIntegrityConfig = {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
'https://btcr2.dev/context/v1'
|
|
319
|
-
],
|
|
312
|
+
// The proof must carry the same array as the update. The cryptosuite copies the
|
|
313
|
+
// document @context into the proof when the document has one, so the two arrays
|
|
314
|
+
// are equal by construction; this value is the fallback for a document without one.
|
|
315
|
+
'@context' : [ ...BTCR2_UPDATE_CONTEXT ],
|
|
320
316
|
cryptosuite : 'bip340-jcs-2025',
|
|
321
317
|
type : 'DataIntegrityProof',
|
|
322
318
|
// The proof names the signing method by absolute DID URL, even when the document
|
package/src/utils/appendix.ts
CHANGED
|
@@ -161,9 +161,10 @@ export class Appendix {
|
|
|
161
161
|
* ```
|
|
162
162
|
* {
|
|
163
163
|
* "@context": [
|
|
164
|
+
* "https://w3id.org/json-ld-patch/v1",
|
|
164
165
|
* "https://w3id.org/zcap/v1",
|
|
165
166
|
* "https://w3id.org/security/data-integrity/v2",
|
|
166
|
-
* "https://
|
|
167
|
+
* "https://btcr2.dev/context/v1"
|
|
167
168
|
* ],
|
|
168
169
|
* "patch": [
|
|
169
170
|
* {
|