@interop/wallet-core 0.41.0 → 0.42.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 +17 -4
- package/dist/clients/rosterPolicy.d.ts +22 -15
- package/dist/clients/rosterPolicy.d.ts.map +1 -1
- package/dist/clients/rosterPolicy.js +32 -15
- package/dist/clients/rosterPolicy.js.map +1 -1
- package/dist/descriptors/index.d.ts +1 -1
- package/dist/descriptors/index.d.ts.map +1 -1
- package/dist/descriptors/index.js +1 -1
- package/dist/descriptors/index.js.map +1 -1
- package/dist/descriptors/logSource.d.ts +58 -6
- package/dist/descriptors/logSource.d.ts.map +1 -1
- package/dist/descriptors/logSource.js +57 -15
- package/dist/descriptors/logSource.js.map +1 -1
- package/dist/enrollment/enrollment.d.ts.map +1 -1
- package/dist/enrollment/enrollment.js +14 -26
- package/dist/enrollment/enrollment.js.map +1 -1
- package/dist/keyring/fetch.d.ts +12 -0
- package/dist/keyring/fetch.d.ts.map +1 -1
- package/dist/keyring/fetch.js +0 -2
- package/dist/keyring/fetch.js.map +1 -1
- package/dist/keyring/index.d.ts +1 -1
- package/dist/keyring/index.d.ts.map +1 -1
- package/dist/keyring/index.js +1 -1
- package/dist/keyring/index.js.map +1 -1
- package/dist/keyring/kdf.d.ts +22 -6
- package/dist/keyring/kdf.d.ts.map +1 -1
- package/dist/keyring/kdf.js +9 -14
- package/dist/keyring/kdf.js.map +1 -1
- package/dist/keys/index.d.ts +1 -1
- package/dist/keys/index.d.ts.map +1 -1
- package/dist/keys/index.js +1 -1
- package/dist/keys/index.js.map +1 -1
- package/dist/keys/rosterLogStore.d.ts +4 -1
- package/dist/keys/rosterLogStore.d.ts.map +1 -1
- package/dist/keys/rosterLogStore.js +13 -16
- package/dist/keys/rosterLogStore.js.map +1 -1
- package/dist/keys/rosterStore.d.ts +13 -1
- package/dist/keys/rosterStore.d.ts.map +1 -1
- package/dist/keys/rosterStore.js +18 -0
- package/dist/keys/rosterStore.js.map +1 -1
- package/dist/keys/userKeyRoster.d.ts +17 -5
- package/dist/keys/userKeyRoster.d.ts.map +1 -1
- package/dist/keys/userKeyRoster.js +38 -13
- package/dist/keys/userKeyRoster.js.map +1 -1
- package/dist/recovery/index.d.ts +14 -12
- package/dist/recovery/index.d.ts.map +1 -1
- package/dist/recovery/index.js +13 -11
- package/dist/recovery/index.js.map +1 -1
- package/dist/recovery/recoveryCode.d.ts +5 -17
- package/dist/recovery/recoveryCode.d.ts.map +1 -1
- package/dist/recovery/recoveryCode.js +4 -14
- package/dist/recovery/recoveryCode.js.map +1 -1
- package/dist/recovery/recoveryDelegation.d.ts +50 -19
- package/dist/recovery/recoveryDelegation.d.ts.map +1 -1
- package/dist/recovery/recoveryDelegation.js +86 -41
- package/dist/recovery/recoveryDelegation.js.map +1 -1
- package/dist/recovery/recoveryWebvh.d.ts +13 -22
- package/dist/recovery/recoveryWebvh.d.ts.map +1 -1
- package/dist/recovery/recoveryWebvh.js +37 -129
- package/dist/recovery/recoveryWebvh.js.map +1 -1
- package/dist/resourceLog/append.d.ts +12 -3
- package/dist/resourceLog/append.d.ts.map +1 -1
- package/dist/resourceLog/append.js +17 -10
- package/dist/resourceLog/append.js.map +1 -1
- package/dist/resourceLog/index.d.ts +1 -1
- package/dist/resourceLog/index.d.ts.map +1 -1
- package/dist/resourceLog/index.js +1 -1
- package/dist/resourceLog/index.js.map +1 -1
- package/dist/resourceLog/pin.d.ts +46 -8
- package/dist/resourceLog/pin.d.ts.map +1 -1
- package/dist/resourceLog/pin.js +32 -7
- package/dist/resourceLog/pin.js.map +1 -1
- package/dist/resourceLog/seal.d.ts +4 -1
- package/dist/resourceLog/seal.d.ts.map +1 -1
- package/dist/resourceLog/seal.js +6 -2
- package/dist/resourceLog/seal.js.map +1 -1
- package/dist/unlock/index.d.ts +40 -0
- package/dist/unlock/index.d.ts.map +1 -0
- package/dist/unlock/index.js +36 -0
- package/dist/unlock/index.js.map +1 -0
- package/dist/unlock/ladder.d.ts +100 -0
- package/dist/unlock/ladder.d.ts.map +1 -0
- package/dist/unlock/ladder.js +144 -0
- package/dist/unlock/ladder.js.map +1 -0
- package/dist/unlock/selfEnroll.d.ts +83 -0
- package/dist/unlock/selfEnroll.d.ts.map +1 -0
- package/dist/unlock/selfEnroll.js +126 -0
- package/dist/unlock/selfEnroll.js.map +1 -0
- package/dist/unlock/standingClient.d.ts +68 -0
- package/dist/unlock/standingClient.d.ts.map +1 -0
- package/dist/unlock/standingClient.js +81 -0
- package/dist/unlock/standingClient.js.map +1 -0
- package/dist/unlock/standingWebvh.d.ts +153 -0
- package/dist/unlock/standingWebvh.d.ts.map +1 -0
- package/dist/unlock/standingWebvh.js +370 -0
- package/dist/unlock/standingWebvh.js.map +1 -0
- package/dist/unlock/unlockRecord.d.ts +207 -0
- package/dist/unlock/unlockRecord.d.ts.map +1 -0
- package/dist/unlock/unlockRecord.js +435 -0
- package/dist/unlock/unlockRecord.js.map +1 -0
- package/dist/webvh/didWebvh.d.ts +94 -6
- package/dist/webvh/didWebvh.d.ts.map +1 -1
- package/dist/webvh/didWebvh.js +175 -19
- package/dist/webvh/didWebvh.js.map +1 -1
- package/dist/webvh/index.d.ts +7 -2
- package/dist/webvh/index.d.ts.map +1 -1
- package/dist/webvh/index.js +7 -2
- package/dist/webvh/index.js.map +1 -1
- package/dist/webvh/keyAgreement.d.ts +22 -6
- package/dist/webvh/keyAgreement.d.ts.map +1 -1
- package/dist/webvh/keyAgreement.js +1 -1
- package/dist/webvh/keyAgreement.js.map +1 -1
- package/dist/webvh/verifyLog.d.ts +15 -2
- package/dist/webvh/verifyLog.d.ts.map +1 -1
- package/dist/webvh/verifyLog.js +22 -3
- package/dist/webvh/verifyLog.js.map +1 -1
- package/package.json +11 -5
- package/dist/recovery/recoveryRecord.d.ts +0 -172
- package/dist/recovery/recoveryRecord.d.ts.map +0 -1
- package/dist/recovery/recoveryRecord.js +0 -288
- package/dist/recovery/recoveryRecord.js.map +0 -1
package/dist/webvh/verifyLog.js
CHANGED
|
@@ -30,6 +30,23 @@ import { readLogFromString, resolveDIDFromLog } from '@interop/did-method-webvh'
|
|
|
30
30
|
import { resourcePath, toUrl } from '@interop/was-client/paths';
|
|
31
31
|
import { DID_LOG_RESOURCE, ID_COLLECTION } from '../space/collections.js';
|
|
32
32
|
import { ResourceLogContinuityError } from '../resourceLog/errors.js';
|
|
33
|
+
import { resourceLogPinId } from '../resourceLog/pin.js';
|
|
34
|
+
/**
|
|
35
|
+
* The pin-slot key for an account's did:webvh log (`id/did.jsonl`) -- what a
|
|
36
|
+
* ceremony taking its own read of the log names its pin by, and what
|
|
37
|
+
* {@link verifyAccountLog} derives internally.
|
|
38
|
+
*
|
|
39
|
+
* @param options {object}
|
|
40
|
+
* @param options.spaceId {string} the account's Space id
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
43
|
+
export function accountLogPinId({ spaceId }) {
|
|
44
|
+
return resourceLogPinId({
|
|
45
|
+
spaceId,
|
|
46
|
+
collectionId: ID_COLLECTION.id,
|
|
47
|
+
resourceId: DID_LOG_RESOURCE
|
|
48
|
+
});
|
|
49
|
+
}
|
|
33
50
|
/**
|
|
34
51
|
* Thrown when the account has published no DID log at all (the resource is
|
|
35
52
|
* absent). Distinguished from every other failure because it is the one
|
|
@@ -133,7 +150,8 @@ export function checkAccountLogContinuity({ log, pin }) {
|
|
|
133
150
|
* @param options.spaceId {string} the account's Space id
|
|
134
151
|
* @param options.host {string} the storage server the account lives on
|
|
135
152
|
* @param [options.pinStore] {ResourceLogPinStore} this client's chain-head
|
|
136
|
-
*
|
|
153
|
+
* pins; the account log's slot is keyed by {@link accountLogPinId} over the
|
|
154
|
+
* `spaceId` above
|
|
137
155
|
* @returns {Promise<object>} the resolved document, the raw log, and the
|
|
138
156
|
* log's effective `updateKeys` / `nextKeyHashes`
|
|
139
157
|
*/
|
|
@@ -159,12 +177,13 @@ export async function verifyAccountLog({ did, spaceId, host, pinStore }) {
|
|
|
159
177
|
'pointer names.');
|
|
160
178
|
}
|
|
161
179
|
if (pinStore) {
|
|
162
|
-
const
|
|
180
|
+
const logId = accountLogPinId({ spaceId });
|
|
181
|
+
const pin = await pinStore.read({ logId });
|
|
163
182
|
const served = checkAccountLogContinuity({ log, pin });
|
|
164
183
|
// Advanced only when the served head is genuinely ahead of the pin: the
|
|
165
184
|
// checks above have already refused everything that is not.
|
|
166
185
|
if (!pin || pin.head !== served.head) {
|
|
167
|
-
await pinStore.write(served);
|
|
186
|
+
await pinStore.write({ logId, pin: served });
|
|
168
187
|
}
|
|
169
188
|
}
|
|
170
189
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyLog.js","sourceRoot":"","sources":["../../src/webvh/verifyLog.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAEhF,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACzE,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"verifyLog.js","sourceRoot":"","sources":["../../src/webvh/verifyLog.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAEhF,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACzE,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAA;AACrE,OAAO,EACL,gBAAgB,EAGjB,MAAM,uBAAuB,CAAA;AAE9B;;;;;;;;GAQ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CAAC;IACD,OAAO;QACL,GAAG,EAAE,QAAQ,CAAC,GAAG;QACjB,GAAG;QACH,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE;QAC1C,aAAa,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa,IAAI,EAAE;KACjD,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interop/wallet-core",
|
|
3
3
|
"description": "Shared wallet-domain logic (WAS sync engine core and wallet Space layout contracts) for Interop wallet apps.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.42.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "pnpm run clear && tsc",
|
|
@@ -90,6 +90,12 @@
|
|
|
90
90
|
"import": "./dist/recovery/index.js",
|
|
91
91
|
"default": "./dist/recovery/index.js"
|
|
92
92
|
},
|
|
93
|
+
"./unlock": {
|
|
94
|
+
"types": "./dist/unlock/index.d.ts",
|
|
95
|
+
"react-native": "./dist/unlock/index.js",
|
|
96
|
+
"import": "./dist/unlock/index.js",
|
|
97
|
+
"default": "./dist/unlock/index.js"
|
|
98
|
+
},
|
|
93
99
|
"./keys": {
|
|
94
100
|
"types": "./dist/keys/index.d.ts",
|
|
95
101
|
"react-native": "./dist/keys/index.js",
|
|
@@ -132,22 +138,22 @@
|
|
|
132
138
|
"types": "dist/index.d.ts",
|
|
133
139
|
"sideEffects": false,
|
|
134
140
|
"dependencies": {
|
|
135
|
-
"@interop/data-integrity-core": "^8.
|
|
141
|
+
"@interop/data-integrity-core": "^8.7.1",
|
|
136
142
|
"@interop/data-integrity-proof": "^3.4.3",
|
|
137
|
-
"@interop/did-method-webvh": "^5.
|
|
143
|
+
"@interop/did-method-webvh": "^5.5.0",
|
|
138
144
|
"@interop/ed25519-signature": "^7.1.4",
|
|
139
145
|
"@interop/ed25519-verification-key": "^8.0.3",
|
|
140
146
|
"@interop/ezcap": "^7.4.1",
|
|
141
147
|
"@interop/security-document-loader": "^10.0.0",
|
|
142
148
|
"@interop/social-core": "^0.8.1",
|
|
143
149
|
"@interop/vc": "^11.0.6",
|
|
144
|
-
"@interop/was-client": "^0.39.
|
|
150
|
+
"@interop/was-client": "^0.39.1",
|
|
145
151
|
"@interop/webkms-client": "^14.7.1",
|
|
146
152
|
"@interop/x25519-key-agreement-key": "^5.2.1",
|
|
147
153
|
"@noble/ciphers": "^2.3.0",
|
|
148
154
|
"@noble/hashes": "^2.3.0",
|
|
149
155
|
"@scure/base": "^2.3.0",
|
|
150
|
-
"byoe-context": "^0.
|
|
156
|
+
"byoe-context": "^0.5.0"
|
|
151
157
|
},
|
|
152
158
|
"devDependencies": {
|
|
153
159
|
"@eslint/js": "^10.0.1",
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import type { IKeyAgreementKey, IKeyResolver, IZcap } from '@interop/data-integrity-core';
|
|
2
|
-
import type { AccountPointer, RecordSigner, SignedRecord } from '../keyring/record.js';
|
|
3
|
-
/**
|
|
4
|
-
* A recovery record's account binding is absent, malformed, or does not
|
|
5
|
-
* verify under the typed code's binding MAC key. Its own class, distinct from
|
|
6
|
-
* a proof or decrypt failure: this is the refusal that says the record's
|
|
7
|
-
* `{ controller, pointer }` core was not written by a holder of this code --
|
|
8
|
-
* a forged record redirecting recovery at another account, or a record from
|
|
9
|
-
* before the account moved hosts (either way the code cannot recover here
|
|
10
|
-
* and must be re-issued).
|
|
11
|
-
*/
|
|
12
|
-
export declare class RecoveryBindingError extends Error {
|
|
13
|
-
constructor(message: string);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* The unwrapped contents of a recovery keyring record: the code-authenticated
|
|
17
|
-
* account binding (controller + pointer) plus the delegation and bind
|
|
18
|
-
* timestamp. `pointer` is required -- a recovery record exists only on WAS
|
|
19
|
-
* deployments (there is nothing to recover toward without a Space).
|
|
20
|
-
*/
|
|
21
|
-
export interface RecoveryRecordContents {
|
|
22
|
-
controller: string;
|
|
23
|
-
pointer: AccountPointer;
|
|
24
|
-
delegation: IZcap;
|
|
25
|
-
createdAt: string;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* A stored recovery record: the shared signed frame plus the account-binding
|
|
29
|
-
* tag the frame proof also covers.
|
|
30
|
-
*/
|
|
31
|
-
export interface SignedRecoveryRecord extends SignedRecord {
|
|
32
|
-
binding: string;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Where a recovery record's proof stands after the unwrap: `'verified'` when
|
|
36
|
-
* the code-derived unlock key signed it (checked before decryption), or a
|
|
37
|
-
* pending marker naming the signer the caller must still check against the
|
|
38
|
-
* account's verified did:webvh document -- the re-mint case, where an enrolled
|
|
39
|
-
* client signed on the code's behalf. The pending case is a value the caller
|
|
40
|
-
* cannot ignore by accident: the shell is not trustworthy until
|
|
41
|
-
* `verifyRecordProof` is run against the document-listed keys. The account
|
|
42
|
-
* the document belongs to is the one the code-authenticated pointer names --
|
|
43
|
-
* the binding is verified either way, so the pending state defers the shell's
|
|
44
|
-
* authenticity only, never the account identity.
|
|
45
|
-
*/
|
|
46
|
-
export type RecoveryRecordProofState = 'verified' | {
|
|
47
|
-
pending: {
|
|
48
|
-
verificationMethod: string;
|
|
49
|
-
keyMultibase: string;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Computes the account-binding tag: HMAC-SHA-256 over the binding values
|
|
54
|
-
* under the code-derived binding MAC key, base64url (no pad). Issuance calls
|
|
55
|
-
* it to stamp the record; recovery recomputes it to verify.
|
|
56
|
-
*
|
|
57
|
-
* @param options {object}
|
|
58
|
-
* @param options.bindingMacKey {Uint8Array} the code-derived MAC key
|
|
59
|
-
* @param options.controller {string} the account did:key
|
|
60
|
-
* @param options.pointer {AccountPointer} the account pointer
|
|
61
|
-
* @returns {string}
|
|
62
|
-
*/
|
|
63
|
-
export declare function computeRecoveryBinding({ bindingMacKey, controller, pointer }: {
|
|
64
|
-
bindingMacKey: Uint8Array;
|
|
65
|
-
controller: string;
|
|
66
|
-
pointer: AccountPointer;
|
|
67
|
-
}): string;
|
|
68
|
-
/**
|
|
69
|
-
* Reads the `binding` frame member off a stored recovery record without
|
|
70
|
-
* decrypting anything. The re-mint path uses it to carry the tag forward
|
|
71
|
-
* verbatim -- it cannot recompute the tag (no code bytes) and does not need
|
|
72
|
-
* to. Refuses a record with no binding: such a record predates the
|
|
73
|
-
* code-authenticated core and cannot be re-minted -- its code must be
|
|
74
|
-
* re-issued.
|
|
75
|
-
*
|
|
76
|
-
* @param options {object}
|
|
77
|
-
* @param options.record {unknown} the stored record envelope
|
|
78
|
-
* @returns {string}
|
|
79
|
-
*/
|
|
80
|
-
export declare function recoveryRecordBinding({ record }: {
|
|
81
|
-
record: unknown;
|
|
82
|
-
}): string;
|
|
83
|
-
/**
|
|
84
|
-
* Wraps the recovery record: controller, pointer, and the pre-minted
|
|
85
|
-
* `did.jsonl` PUT delegation, encrypted under the code's unlock KAK via the
|
|
86
|
-
* keyring EDV cipher context, then signed into the same frame the keyring
|
|
87
|
-
* record uses -- with the account-binding tag as one more frame member the
|
|
88
|
-
* proof covers. Issuance passes the code-derived `bindingMacKey` (the tag is
|
|
89
|
-
* computed here) and the code-derived unlock signer; the revocation cascade's
|
|
90
|
-
* re-mint path passes the standing record's `binding` verbatim and an
|
|
91
|
-
* enrolled client's account signer (see this module's header for the policy
|
|
92
|
-
* the reader applies to the two). Exactly one of the two binding inputs must
|
|
93
|
-
* be given.
|
|
94
|
-
*
|
|
95
|
-
* @param options {object}
|
|
96
|
-
* @param options.controller {string} the account did:key
|
|
97
|
-
* @param options.pointer {AccountPointer} the account pointer
|
|
98
|
-
* @param options.delegation {IZcap} the PUT-on-`did.jsonl` delegation to the
|
|
99
|
-
* code-derived signing DID
|
|
100
|
-
* @param options.keyAgreementKey {IKeyAgreementKey} the code's unlock KAK --
|
|
101
|
-
* its public half is all the wrap uses (sealing needs no key-agreement
|
|
102
|
-
* secret), which is exactly what lets the re-mint path re-seal a record it
|
|
103
|
-
* can never open
|
|
104
|
-
* @param options.signer {RecordSigner} the signing key: the code's unlock
|
|
105
|
-
* key at issuance, an enrolled client's account key on a re-mint
|
|
106
|
-
* @param [options.bindingMacKey] {Uint8Array} the code-derived binding MAC
|
|
107
|
-
* key -- the issuance path, which computes the tag
|
|
108
|
-
* @param [options.binding] {string} the standing record's tag, carried
|
|
109
|
-
* forward verbatim -- the re-mint path, which cannot recompute it
|
|
110
|
-
* @param [options.createdAt] {string} the bind timestamp to stamp, as an ISO
|
|
111
|
-
* string; defaults to now. Supplied by a caller that pins record freshness.
|
|
112
|
-
* @returns {Promise<SignedRecoveryRecord>}
|
|
113
|
-
*/
|
|
114
|
-
export declare function wrapRecoveryRecord({ controller, pointer, delegation, keyAgreementKey, signer, bindingMacKey, binding, createdAt }: {
|
|
115
|
-
controller: string;
|
|
116
|
-
pointer: AccountPointer;
|
|
117
|
-
delegation: IZcap;
|
|
118
|
-
keyAgreementKey: IKeyAgreementKey;
|
|
119
|
-
signer: RecordSigner;
|
|
120
|
-
bindingMacKey?: Uint8Array;
|
|
121
|
-
binding?: string;
|
|
122
|
-
createdAt?: string;
|
|
123
|
-
}): Promise<SignedRecoveryRecord>;
|
|
124
|
-
/**
|
|
125
|
-
* Unwraps and validates a recovery record: the ordinary keyring-record checks
|
|
126
|
-
* plus the required pointer, delegation, and account binding. A record
|
|
127
|
-
* without a delegation is not a recovery record (an ordinary keyring record
|
|
128
|
-
* found under a code's unlock Space would mean a corrupted issuance) and is
|
|
129
|
-
* refused.
|
|
130
|
-
*
|
|
131
|
-
* The account binding is verified before the contents are returned: the
|
|
132
|
-
* decrypted `{ controller, pointer }` must carry the tag the code-derived
|
|
133
|
-
* MAC key computes over them, or the record is refused as forged
|
|
134
|
-
* ({@link RecoveryBindingError}) -- the check that closes the host-forgery
|
|
135
|
-
* redirect, since the host never holds the MAC key. Nothing downstream may
|
|
136
|
-
* trust the pointer before this returns.
|
|
137
|
-
*
|
|
138
|
-
* Proof verification is mixed-signer and ordered deliberately. A proof by the
|
|
139
|
-
* code's own unlock key is verified BEFORE decryption -- the strong path,
|
|
140
|
-
* where the typed code alone establishes what may have signed the record. A
|
|
141
|
-
* proof by any other key can only be checked after decryption, because the
|
|
142
|
-
* re-minting client is knowable only once the code-authenticated pointer says
|
|
143
|
-
* which account this is and that account's log has been verified; the
|
|
144
|
-
* contents come back with a pending proof state naming the signer, and the
|
|
145
|
-
* caller completes the check with {@link verifyRecordProof} against the
|
|
146
|
-
* document's keys. That second phase is what makes an unexpected signer
|
|
147
|
-
* refuse: a record whose proof belongs to neither class ends in a
|
|
148
|
-
* `RecordProofError` there.
|
|
149
|
-
*
|
|
150
|
-
* @param options {object}
|
|
151
|
-
* @param options.record {unknown} the stored `{ version, encryption,
|
|
152
|
-
* wrapped, binding, proof }` envelope
|
|
153
|
-
* @param options.keyAgreementKey {IKeyAgreementKey} the code's unlock KAK
|
|
154
|
-
* @param options.keyResolver {IKeyResolver}
|
|
155
|
-
* @param options.expectedKeyMultibase {string} the code-derived unlock
|
|
156
|
-
* signing key's multibase
|
|
157
|
-
* @param options.bindingMacKey {Uint8Array} the code-derived binding MAC
|
|
158
|
-
* key the record's account binding must verify under
|
|
159
|
-
* @returns {Promise<{ contents: RecoveryRecordContents,
|
|
160
|
-
* proofState: RecoveryRecordProofState }>}
|
|
161
|
-
*/
|
|
162
|
-
export declare function unwrapRecoveryRecord({ record, keyAgreementKey, keyResolver, expectedKeyMultibase, bindingMacKey }: {
|
|
163
|
-
record: unknown;
|
|
164
|
-
keyAgreementKey: IKeyAgreementKey;
|
|
165
|
-
keyResolver: IKeyResolver;
|
|
166
|
-
expectedKeyMultibase: string;
|
|
167
|
-
bindingMacKey: Uint8Array;
|
|
168
|
-
}): Promise<{
|
|
169
|
-
contents: RecoveryRecordContents;
|
|
170
|
-
proofState: RecoveryRecordProofState;
|
|
171
|
-
}>;
|
|
172
|
-
//# sourceMappingURL=recoveryRecord.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recoveryRecord.d.ts","sourceRoot":"","sources":["../../src/recovery/recoveryRecord.ts"],"names":[],"mappings":"AA+CA,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,KAAK,EACN,MAAM,8BAA8B,CAAA;AAcrC,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,YAAY,EACb,MAAM,sBAAsB,CAAA;AAQ7B;;;;;;;;GAQG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,cAAc,CAAA;IACvB,UAAU,EAAE,KAAK,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACxD,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,wBAAwB,GAClC,UAAU,GAAG;IAAE,OAAO,EAAE;QAAE,kBAAkB,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAA;AAyBhF;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,aAAa,EACb,UAAU,EACV,OAAO,EACR,EAAE;IACD,aAAa,EAAE,UAAU,CAAA;IACzB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,cAAc,CAAA;CACxB,GAAG,MAAM,CAIT;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,CAS7E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAsB,kBAAkB,CAAC,EACvC,UAAU,EACV,OAAO,EACP,UAAU,EACV,eAAe,EACf,MAAM,EACN,aAAa,EACb,OAAO,EACP,SAAS,EACV,EAAE;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,cAAc,CAAA;IACvB,UAAU,EAAE,KAAK,CAAA;IACjB,eAAe,EAAE,gBAAgB,CAAA;IACjC,MAAM,EAAE,YAAY,CAAA;IACpB,aAAa,CAAC,EAAE,UAAU,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAiChC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,MAAM,EACN,eAAe,EACf,WAAW,EACX,oBAAoB,EACpB,aAAa,EACd,EAAE;IACD,MAAM,EAAE,OAAO,CAAA;IACf,eAAe,EAAE,gBAAgB,CAAA;IACjC,WAAW,EAAE,YAAY,CAAA;IACzB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,aAAa,EAAE,UAAU,CAAA;CAC1B,GAAG,OAAO,CAAC;IACV,QAAQ,EAAE,sBAAsB,CAAA;IAChC,UAAU,EAAE,wBAAwB,CAAA;CACrC,CAAC,CAqFD"}
|
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2026 Interop Alliance. All rights reserved.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* The recovery keyring record codec: the `{ version, encryption, wrapped,
|
|
6
|
-
* binding, proof }` envelope stored as the one resource of a recovery code's
|
|
7
|
-
* unlock Space. Its plaintext is the ordinary keyring record's (controller,
|
|
8
|
-
* account pointer) PLUS the pre-minted PUT-on-`did.jsonl` delegation -- the
|
|
9
|
-
* narrow zcap bridge that lets the code-derived client write its
|
|
10
|
-
* self-enrolling log continuation. It carries **no key material of any
|
|
11
|
-
* kind**: never a seed, never a user key wrap (wraps live doc-and-roster
|
|
12
|
-
* only), so the record stays a pure pointer.
|
|
13
|
-
*
|
|
14
|
-
* The wrap reuses the keyring record construction (cipher context,
|
|
15
|
-
* record-own epoch, and signed frame alike), so a recovery record IS a
|
|
16
|
-
* keyring record to every generic consumer -- only the recovery flow demands
|
|
17
|
-
* the delegation and the binding.
|
|
18
|
-
*
|
|
19
|
-
* The record splits into a code-authenticated core and a re-mintable shell.
|
|
20
|
-
* The core is the account binding `{ controller, pointer }`, authenticated by
|
|
21
|
-
* the `binding` frame member: an HMAC tag under a key derived from the code
|
|
22
|
-
* bytes, computed at issuance and verified at recovery BEFORE the pointer is
|
|
23
|
-
* trusted. Only the issuer and the code holder ever hold that key -- the
|
|
24
|
-
* storage host never does -- so a host-forged record pointing recovery at
|
|
25
|
-
* another account fails the tag however it is encrypted or signed. The tag
|
|
26
|
-
* rides the frame in the clear (it reveals nothing) so the re-mint path,
|
|
27
|
-
* which cannot decrypt the record or recompute the tag, preserves it
|
|
28
|
-
* verbatim; the binding values themselves stay inside the plaintext. The
|
|
29
|
-
* consequence: a re-mint can never change the pointer, and an account that
|
|
30
|
-
* moves hosts must re-issue its codes.
|
|
31
|
-
*
|
|
32
|
-
* The shell is the delegation and the frame proof, and its signer is mixed.
|
|
33
|
-
* At issuance the record is signed by the code-derived unlock key, the one a
|
|
34
|
-
* typed code re-derives, so recovery verifies the proof before decrypting.
|
|
35
|
-
* The revocation cascade's re-mint path holds only the code's KAK public
|
|
36
|
-
* half plus an enrolled client's account key, so it re-PUTs the record
|
|
37
|
-
* signed by that client's account verification method instead. This codec is
|
|
38
|
-
* agnostic -- it signs with what it is given -- and the reader carries the
|
|
39
|
-
* policy: a proof by the expected unlock key verifies up front, and anything
|
|
40
|
-
* else comes back marked unverified, for the caller to check against the
|
|
41
|
-
* verified did:webvh document of the account the code-authenticated pointer
|
|
42
|
-
* names.
|
|
43
|
-
*/
|
|
44
|
-
import { base64urlnopad } from '@scure/base';
|
|
45
|
-
import { equalBytes } from '@noble/ciphers/utils.js';
|
|
46
|
-
import { hmac } from '@noble/hashes/hmac.js';
|
|
47
|
-
import { sha256 } from '@noble/hashes/sha2.js';
|
|
48
|
-
import { KEYRING_RECORD_VERSION, mintRecordEncryption, parseRecordCreatedAt, parseRecordFrame, parseRecordPointer, recordCipher, recordCreatedAtStamp, recordProofKeyMultibase, recordSealCipher, signRecordFrame, verifyRecordProof } from '../keyring/record.js';
|
|
49
|
-
/**
|
|
50
|
-
* The context label mixed into the binding MAC input, versioning the tag
|
|
51
|
-
* construction. Permanent -- changing it orphans every issued code.
|
|
52
|
-
*/
|
|
53
|
-
const RECOVERY_BINDING_CONTEXT = 'freewallet/recovery/binding/v1';
|
|
54
|
-
/**
|
|
55
|
-
* A recovery record's account binding is absent, malformed, or does not
|
|
56
|
-
* verify under the typed code's binding MAC key. Its own class, distinct from
|
|
57
|
-
* a proof or decrypt failure: this is the refusal that says the record's
|
|
58
|
-
* `{ controller, pointer }` core was not written by a holder of this code --
|
|
59
|
-
* a forged record redirecting recovery at another account, or a record from
|
|
60
|
-
* before the account moved hosts (either way the code cannot recover here
|
|
61
|
-
* and must be re-issued).
|
|
62
|
-
*/
|
|
63
|
-
export class RecoveryBindingError extends Error {
|
|
64
|
-
constructor(message) {
|
|
65
|
-
super(message);
|
|
66
|
-
this.name = 'RecoveryBindingError';
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* The deterministic MAC input over a record's account binding: a JSON array
|
|
71
|
-
* of the context label and the binding values, so no delimiter ambiguity can
|
|
72
|
-
* make two bindings collide.
|
|
73
|
-
*/
|
|
74
|
-
function bindingMacInput({ controller, pointer }) {
|
|
75
|
-
return new TextEncoder().encode(JSON.stringify([
|
|
76
|
-
RECOVERY_BINDING_CONTEXT,
|
|
77
|
-
controller,
|
|
78
|
-
pointer.did ?? '',
|
|
79
|
-
pointer.spaceId,
|
|
80
|
-
pointer.host
|
|
81
|
-
]));
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Computes the account-binding tag: HMAC-SHA-256 over the binding values
|
|
85
|
-
* under the code-derived binding MAC key, base64url (no pad). Issuance calls
|
|
86
|
-
* it to stamp the record; recovery recomputes it to verify.
|
|
87
|
-
*
|
|
88
|
-
* @param options {object}
|
|
89
|
-
* @param options.bindingMacKey {Uint8Array} the code-derived MAC key
|
|
90
|
-
* @param options.controller {string} the account did:key
|
|
91
|
-
* @param options.pointer {AccountPointer} the account pointer
|
|
92
|
-
* @returns {string}
|
|
93
|
-
*/
|
|
94
|
-
export function computeRecoveryBinding({ bindingMacKey, controller, pointer }) {
|
|
95
|
-
return base64urlnopad.encode(hmac(sha256, bindingMacKey, bindingMacInput({ controller, pointer })));
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Reads the `binding` frame member off a stored recovery record without
|
|
99
|
-
* decrypting anything. The re-mint path uses it to carry the tag forward
|
|
100
|
-
* verbatim -- it cannot recompute the tag (no code bytes) and does not need
|
|
101
|
-
* to. Refuses a record with no binding: such a record predates the
|
|
102
|
-
* code-authenticated core and cannot be re-minted -- its code must be
|
|
103
|
-
* re-issued.
|
|
104
|
-
*
|
|
105
|
-
* @param options {object}
|
|
106
|
-
* @param options.record {unknown} the stored record envelope
|
|
107
|
-
* @returns {string}
|
|
108
|
-
*/
|
|
109
|
-
export function recoveryRecordBinding({ record }) {
|
|
110
|
-
const { binding } = (record ?? {});
|
|
111
|
-
if (typeof binding !== 'string' || !binding) {
|
|
112
|
-
throw new RecoveryBindingError('The recovery record carries no code-authenticated account binding; ' +
|
|
113
|
-
'the recovery code must be re-issued.');
|
|
114
|
-
}
|
|
115
|
-
return binding;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Wraps the recovery record: controller, pointer, and the pre-minted
|
|
119
|
-
* `did.jsonl` PUT delegation, encrypted under the code's unlock KAK via the
|
|
120
|
-
* keyring EDV cipher context, then signed into the same frame the keyring
|
|
121
|
-
* record uses -- with the account-binding tag as one more frame member the
|
|
122
|
-
* proof covers. Issuance passes the code-derived `bindingMacKey` (the tag is
|
|
123
|
-
* computed here) and the code-derived unlock signer; the revocation cascade's
|
|
124
|
-
* re-mint path passes the standing record's `binding` verbatim and an
|
|
125
|
-
* enrolled client's account signer (see this module's header for the policy
|
|
126
|
-
* the reader applies to the two). Exactly one of the two binding inputs must
|
|
127
|
-
* be given.
|
|
128
|
-
*
|
|
129
|
-
* @param options {object}
|
|
130
|
-
* @param options.controller {string} the account did:key
|
|
131
|
-
* @param options.pointer {AccountPointer} the account pointer
|
|
132
|
-
* @param options.delegation {IZcap} the PUT-on-`did.jsonl` delegation to the
|
|
133
|
-
* code-derived signing DID
|
|
134
|
-
* @param options.keyAgreementKey {IKeyAgreementKey} the code's unlock KAK --
|
|
135
|
-
* its public half is all the wrap uses (sealing needs no key-agreement
|
|
136
|
-
* secret), which is exactly what lets the re-mint path re-seal a record it
|
|
137
|
-
* can never open
|
|
138
|
-
* @param options.signer {RecordSigner} the signing key: the code's unlock
|
|
139
|
-
* key at issuance, an enrolled client's account key on a re-mint
|
|
140
|
-
* @param [options.bindingMacKey] {Uint8Array} the code-derived binding MAC
|
|
141
|
-
* key -- the issuance path, which computes the tag
|
|
142
|
-
* @param [options.binding] {string} the standing record's tag, carried
|
|
143
|
-
* forward verbatim -- the re-mint path, which cannot recompute it
|
|
144
|
-
* @param [options.createdAt] {string} the bind timestamp to stamp, as an ISO
|
|
145
|
-
* string; defaults to now. Supplied by a caller that pins record freshness.
|
|
146
|
-
* @returns {Promise<SignedRecoveryRecord>}
|
|
147
|
-
*/
|
|
148
|
-
export async function wrapRecoveryRecord({ controller, pointer, delegation, keyAgreementKey, signer, bindingMacKey, binding, createdAt }) {
|
|
149
|
-
if ((bindingMacKey === undefined) === (binding === undefined)) {
|
|
150
|
-
throw new Error('Exactly one of bindingMacKey (issuance) or binding (re-mint) is ' +
|
|
151
|
-
'required.');
|
|
152
|
-
}
|
|
153
|
-
const tag = bindingMacKey !== undefined
|
|
154
|
-
? computeRecoveryBinding({ bindingMacKey, controller, pointer })
|
|
155
|
-
: binding;
|
|
156
|
-
const encryption = await mintRecordEncryption({ keyAgreementKey });
|
|
157
|
-
const cipher = await recordSealCipher({ encryption });
|
|
158
|
-
const data = {
|
|
159
|
-
controller,
|
|
160
|
-
pointer: {
|
|
161
|
-
...(pointer.did ? { did: pointer.did } : {}),
|
|
162
|
-
spaceId: pointer.spaceId,
|
|
163
|
-
host: pointer.host
|
|
164
|
-
},
|
|
165
|
-
delegation,
|
|
166
|
-
createdAt: recordCreatedAtStamp({ createdAt })
|
|
167
|
-
};
|
|
168
|
-
const { envelope } = await cipher.encrypt({
|
|
169
|
-
data: data
|
|
170
|
-
});
|
|
171
|
-
return (await signRecordFrame({
|
|
172
|
-
version: KEYRING_RECORD_VERSION,
|
|
173
|
-
encryption,
|
|
174
|
-
wrapped: envelope,
|
|
175
|
-
signer,
|
|
176
|
-
members: { binding: tag }
|
|
177
|
-
}));
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Unwraps and validates a recovery record: the ordinary keyring-record checks
|
|
181
|
-
* plus the required pointer, delegation, and account binding. A record
|
|
182
|
-
* without a delegation is not a recovery record (an ordinary keyring record
|
|
183
|
-
* found under a code's unlock Space would mean a corrupted issuance) and is
|
|
184
|
-
* refused.
|
|
185
|
-
*
|
|
186
|
-
* The account binding is verified before the contents are returned: the
|
|
187
|
-
* decrypted `{ controller, pointer }` must carry the tag the code-derived
|
|
188
|
-
* MAC key computes over them, or the record is refused as forged
|
|
189
|
-
* ({@link RecoveryBindingError}) -- the check that closes the host-forgery
|
|
190
|
-
* redirect, since the host never holds the MAC key. Nothing downstream may
|
|
191
|
-
* trust the pointer before this returns.
|
|
192
|
-
*
|
|
193
|
-
* Proof verification is mixed-signer and ordered deliberately. A proof by the
|
|
194
|
-
* code's own unlock key is verified BEFORE decryption -- the strong path,
|
|
195
|
-
* where the typed code alone establishes what may have signed the record. A
|
|
196
|
-
* proof by any other key can only be checked after decryption, because the
|
|
197
|
-
* re-minting client is knowable only once the code-authenticated pointer says
|
|
198
|
-
* which account this is and that account's log has been verified; the
|
|
199
|
-
* contents come back with a pending proof state naming the signer, and the
|
|
200
|
-
* caller completes the check with {@link verifyRecordProof} against the
|
|
201
|
-
* document's keys. That second phase is what makes an unexpected signer
|
|
202
|
-
* refuse: a record whose proof belongs to neither class ends in a
|
|
203
|
-
* `RecordProofError` there.
|
|
204
|
-
*
|
|
205
|
-
* @param options {object}
|
|
206
|
-
* @param options.record {unknown} the stored `{ version, encryption,
|
|
207
|
-
* wrapped, binding, proof }` envelope
|
|
208
|
-
* @param options.keyAgreementKey {IKeyAgreementKey} the code's unlock KAK
|
|
209
|
-
* @param options.keyResolver {IKeyResolver}
|
|
210
|
-
* @param options.expectedKeyMultibase {string} the code-derived unlock
|
|
211
|
-
* signing key's multibase
|
|
212
|
-
* @param options.bindingMacKey {Uint8Array} the code-derived binding MAC
|
|
213
|
-
* key the record's account binding must verify under
|
|
214
|
-
* @returns {Promise<{ contents: RecoveryRecordContents,
|
|
215
|
-
* proofState: RecoveryRecordProofState }>}
|
|
216
|
-
*/
|
|
217
|
-
export async function unwrapRecoveryRecord({ record, keyAgreementKey, keyResolver, expectedKeyMultibase, bindingMacKey }) {
|
|
218
|
-
const { encryption, wrapped, proof } = parseRecordFrame({
|
|
219
|
-
record,
|
|
220
|
-
label: 'recovery'
|
|
221
|
-
});
|
|
222
|
-
const binding = recoveryRecordBinding({ record });
|
|
223
|
-
// `parseRecordFrame` shape-checks the proof of a current-version frame, so
|
|
224
|
-
// it is present here.
|
|
225
|
-
const verificationMethod = proof.verificationMethod;
|
|
226
|
-
const keyMultibase = recordProofKeyMultibase({
|
|
227
|
-
verificationMethod,
|
|
228
|
-
label: 'recovery'
|
|
229
|
-
});
|
|
230
|
-
let proofState = {
|
|
231
|
-
pending: { verificationMethod, keyMultibase }
|
|
232
|
-
};
|
|
233
|
-
if (keyMultibase === expectedKeyMultibase) {
|
|
234
|
-
await verifyRecordProof({
|
|
235
|
-
record,
|
|
236
|
-
allowedKeyMultibases: expectedKeyMultibase,
|
|
237
|
-
label: 'recovery'
|
|
238
|
-
});
|
|
239
|
-
proofState = 'verified';
|
|
240
|
-
}
|
|
241
|
-
const cipher = await recordCipher({
|
|
242
|
-
keyAgreementKey,
|
|
243
|
-
keyResolver,
|
|
244
|
-
encryption
|
|
245
|
-
});
|
|
246
|
-
const plaintext = (await cipher.decrypt({
|
|
247
|
-
envelope: wrapped
|
|
248
|
-
}));
|
|
249
|
-
if (typeof plaintext.controller !== 'string' || !plaintext.controller) {
|
|
250
|
-
throw new Error('Recovery record is missing a controller.');
|
|
251
|
-
}
|
|
252
|
-
const pointer = parseRecordPointer(plaintext.pointer);
|
|
253
|
-
if (!pointer) {
|
|
254
|
-
throw new Error('Recovery record is missing its account pointer.');
|
|
255
|
-
}
|
|
256
|
-
if (plaintext.delegation === null ||
|
|
257
|
-
typeof plaintext.delegation !== 'object') {
|
|
258
|
-
throw new Error('Recovery record is missing its did.jsonl delegation.');
|
|
259
|
-
}
|
|
260
|
-
const createdAt = parseRecordCreatedAt({
|
|
261
|
-
value: plaintext.createdAt,
|
|
262
|
-
label: 'Recovery'
|
|
263
|
-
});
|
|
264
|
-
const expectedTag = hmac(sha256, bindingMacKey, bindingMacInput({ controller: plaintext.controller, pointer }));
|
|
265
|
-
let servedTag;
|
|
266
|
-
try {
|
|
267
|
-
servedTag = base64urlnopad.decode(binding);
|
|
268
|
-
}
|
|
269
|
-
catch {
|
|
270
|
-
servedTag = null;
|
|
271
|
-
}
|
|
272
|
-
// `equalBytes` is @noble/ciphers' authentication-tag comparison (no early
|
|
273
|
-
// exit), so the check leaks nothing through timing.
|
|
274
|
-
if (servedTag === null || !equalBytes(servedTag, expectedTag)) {
|
|
275
|
-
throw new RecoveryBindingError("The recovery record's account binding does not verify under this " +
|
|
276
|
-
'code; the record is refused as forged.');
|
|
277
|
-
}
|
|
278
|
-
return {
|
|
279
|
-
contents: {
|
|
280
|
-
controller: plaintext.controller,
|
|
281
|
-
pointer,
|
|
282
|
-
delegation: plaintext.delegation,
|
|
283
|
-
createdAt
|
|
284
|
-
},
|
|
285
|
-
proofState
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
//# sourceMappingURL=recoveryRecord.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recoveryRecord.js","sourceRoot":"","sources":["../../src/recovery/recoveryRecord.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAM9C,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACpB,uBAAuB,EACvB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EAClB,MAAM,sBAAsB,CAAA;AAO7B;;;GAGG;AACH,MAAM,wBAAwB,GAAG,gCAAgC,CAAA;AAEjE;;;;;;;;GAQG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACpC,CAAC;CACF;AAsCD;;;;GAIG;AACH,SAAS,eAAe,CAAC,EACvB,UAAU,EACV,OAAO,EAIR;IACC,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAC7B,IAAI,CAAC,SAAS,CAAC;QACb,wBAAwB;QACxB,UAAU;QACV,OAAO,CAAC,GAAG,IAAI,EAAE;QACjB,OAAO,CAAC,OAAO;QACf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