@bsv/dpp-core 0.3.0-beta.1
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 +58 -0
- package/README.md +95 -0
- package/dist/acceptance.d.ts +100 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +202 -0
- package/dist/acceptance.js.map +1 -0
- package/dist/anchor.d.ts +66 -0
- package/dist/anchor.d.ts.map +1 -0
- package/dist/anchor.js +145 -0
- package/dist/anchor.js.map +1 -0
- package/dist/attestation.d.ts +40 -0
- package/dist/attestation.d.ts.map +1 -0
- package/dist/attestation.js +111 -0
- package/dist/attestation.js.map +1 -0
- package/dist/blob.d.ts +11 -0
- package/dist/blob.d.ts.map +1 -0
- package/dist/blob.js +16 -0
- package/dist/blob.js.map +1 -0
- package/dist/canonical.d.ts +32 -0
- package/dist/canonical.d.ts.map +1 -0
- package/dist/canonical.js +54 -0
- package/dist/canonical.js.map +1 -0
- package/dist/canonicalJson.d.ts +22 -0
- package/dist/canonicalJson.d.ts.map +1 -0
- package/dist/canonicalJson.js +60 -0
- package/dist/canonicalJson.js.map +1 -0
- package/dist/codec.d.ts +45 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +459 -0
- package/dist/codec.js.map +1 -0
- package/dist/constants.d.ts +150 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +179 -0
- package/dist/constants.js.map +1 -0
- package/dist/did.d.ts +37 -0
- package/dist/did.d.ts.map +1 -0
- package/dist/did.js +129 -0
- package/dist/did.js.map +1 -0
- package/dist/evidence.d.ts +224 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +716 -0
- package/dist/evidence.js.map +1 -0
- package/dist/evidencePackage.d.ts +114 -0
- package/dist/evidencePackage.d.ts.map +1 -0
- package/dist/evidencePackage.js +164 -0
- package/dist/evidencePackage.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/owner.d.ts +135 -0
- package/dist/owner.d.ts.map +1 -0
- package/dist/owner.js +181 -0
- package/dist/owner.js.map +1 -0
- package/dist/publisherPolicy.d.ts +70 -0
- package/dist/publisherPolicy.d.ts.map +1 -0
- package/dist/publisherPolicy.js +186 -0
- package/dist/publisherPolicy.js.map +1 -0
- package/dist/signatures.d.ts +84 -0
- package/dist/signatures.d.ts.map +1 -0
- package/dist/signatures.js +137 -0
- package/dist/signatures.js.map +1 -0
- package/dist/transition.d.ts +29 -0
- package/dist/transition.d.ts.map +1 -0
- package/dist/transition.js +117 -0
- package/dist/transition.js.map +1 -0
- package/dist/types.d.ts +135 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/verifyChain.d.ts +152 -0
- package/dist/verifyChain.d.ts.map +1 -0
- package/dist/verifyChain.js +314 -0
- package/dist/verifyChain.js.map +1 -0
- package/package.json +46 -0
- package/schemas/capabilities.schema.json +129 -0
- package/schemas/epcis-import.schema.json +212 -0
- package/schemas/evidence-export.schema.json +67 -0
- package/schemas/evidence-package.schema.json +307 -0
- package/schemas/native-evidence-extension.schema.json +66 -0
- package/schemas/paginated-history.schema.json +32 -0
- package/schemas/passport-projection.schema.json +151 -0
- package/schemas/passport-source.schema.json +370 -0
- package/schemas/profile-evidence.schema.json +706 -0
- package/schemas/publisher-policy.schema.json +173 -0
- package/schemas/verification-report.schema.json +397 -0
package/dist/codec.js
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import { LockingScript, OP, PublicKey, Utils } from '@bsv/sdk';
|
|
2
|
+
import { DPP_OPS, DPP_OPS_V2, FIELD_COUNT, FIELD_COUNT_V2, MAX_ACTOR_KEY_ID_BYTES, MAX_EVENT_DATA_BYTES_V2, MAX_PASSPORT_ID_BYTES, MAX_PAYLOAD_PUBLIC_BYTES_V2, NO_EVENT_OPS, OUTPOINT_FIELD_BYTES, PROTOCOL_MARKER, STANDARD_VERSION, STANDARD_VERSION_V2, } from './constants.js';
|
|
3
|
+
/** Thrown when a script does not carry a well-formed DPP output of a version this reader decodes. */
|
|
4
|
+
export class DppFormatError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'DppFormatError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Minimal-push encoding, verbatim from @bsv/sdk's PushDrop template (it is
|
|
12
|
+
* module-local there and not exported). Produces scripts byte-identical to
|
|
13
|
+
* PushDrop.lock() so connected-path wallets and explorers see the same shape.
|
|
14
|
+
*/
|
|
15
|
+
function minimalChunk(data) {
|
|
16
|
+
if (data.length === 0)
|
|
17
|
+
return { op: 0 };
|
|
18
|
+
if (data.length === 1 && data[0] === 0)
|
|
19
|
+
return { op: 0 };
|
|
20
|
+
if (data.length === 1 && data[0] > 0 && data[0] <= 16)
|
|
21
|
+
return { op: 0x50 + data[0] };
|
|
22
|
+
if (data.length === 1 && data[0] === 0x81)
|
|
23
|
+
return { op: 0x4f };
|
|
24
|
+
if (data.length <= 75)
|
|
25
|
+
return { op: data.length, data };
|
|
26
|
+
if (data.length <= 255)
|
|
27
|
+
return { op: 0x4c, data };
|
|
28
|
+
if (data.length <= 65535)
|
|
29
|
+
return { op: 0x4d, data };
|
|
30
|
+
return { op: 0x4e, data };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Inverse of minimal-push encoding for a single chunk. Unlike the SDK's
|
|
34
|
+
* PushDrop.decode, OP_0 maps to the EMPTY field (not [0x00]) - the standard's
|
|
35
|
+
* value domain has zero-length fields but never a lone 0x00 byte.
|
|
36
|
+
* Non-minimal pushes are accepted (tolerant read; field bytes, and therefore
|
|
37
|
+
* signature preimages, are unaffected by push encoding).
|
|
38
|
+
*/
|
|
39
|
+
function chunkToField(chunk) {
|
|
40
|
+
if (chunk.data != null && chunk.data.length > 0) {
|
|
41
|
+
return chunk.op >= 1 && chunk.op <= 0x4e ? chunk.data : null;
|
|
42
|
+
}
|
|
43
|
+
if (chunk.op === 0)
|
|
44
|
+
return [];
|
|
45
|
+
if (chunk.op >= 0x51 && chunk.op <= 0x60)
|
|
46
|
+
return [chunk.op - 0x50];
|
|
47
|
+
if (chunk.op === 0x4f)
|
|
48
|
+
return [0x81];
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
/** Whether signable content, of either version, is version 2. */
|
|
52
|
+
export function isV2Data(d) {
|
|
53
|
+
return d.version === STANDARD_VERSION_V2;
|
|
54
|
+
}
|
|
55
|
+
/** Fields 1–12 (the signable content) of a version 1 state as raw wire bytes, in standard order. */
|
|
56
|
+
export function dataFields(d) {
|
|
57
|
+
return [
|
|
58
|
+
Utils.toArray(PROTOCOL_MARKER, 'utf8'),
|
|
59
|
+
Utils.toArray(STANDARD_VERSION, 'utf8'),
|
|
60
|
+
Utils.toArray(d.passportId, 'utf8'),
|
|
61
|
+
Utils.toArray(d.op, 'utf8'),
|
|
62
|
+
Utils.toArray(d.timestamp, 'utf8'),
|
|
63
|
+
Utils.toArray(d.ownerIdentityKey, 'hex'),
|
|
64
|
+
Utils.toArray(d.actorIdentityKey, 'hex'),
|
|
65
|
+
Utils.toArray(d.actorKeyId, 'utf8'),
|
|
66
|
+
Utils.toArray(d.eventData, 'utf8'),
|
|
67
|
+
Utils.toArray(d.payloadPublic, 'utf8'),
|
|
68
|
+
Utils.toArray(d.payloadOwnerHash, 'hex'),
|
|
69
|
+
Utils.toArray(d.previousTxid, 'hex'),
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
/** An outpoint as the version 2 fields 12 and 13 carry it: 32 txid bytes in display order, then a big-endian uint32 index. */
|
|
73
|
+
export function outpointFieldBytes(outpoint) {
|
|
74
|
+
if (outpoint == null)
|
|
75
|
+
return [];
|
|
76
|
+
const txid = Utils.toArray(outpoint.txid, 'hex');
|
|
77
|
+
if (txid.length !== 32)
|
|
78
|
+
throw new DppFormatError('an outpoint txid must be 32 bytes');
|
|
79
|
+
const index = outpoint.outputIndex;
|
|
80
|
+
if (!Number.isInteger(index) || index < 0 || index > 0xffffffff) {
|
|
81
|
+
throw new DppFormatError('an outpoint output index must be an unsigned 32-bit integer');
|
|
82
|
+
}
|
|
83
|
+
return [...txid, (index >>> 24) & 0xff, (index >>> 16) & 0xff, (index >>> 8) & 0xff, index & 0xff];
|
|
84
|
+
}
|
|
85
|
+
/** Fields 1–15 (the signable content) of a version 2 state as raw wire bytes, in standard order. */
|
|
86
|
+
export function dataFieldsV2(d) {
|
|
87
|
+
const predecessor = d.previousTxid === '' ? null : { txid: d.previousTxid, outputIndex: d.previousOutputIndex ?? -1 };
|
|
88
|
+
return [
|
|
89
|
+
Utils.toArray(PROTOCOL_MARKER, 'utf8'),
|
|
90
|
+
Utils.toArray(STANDARD_VERSION_V2, 'utf8'),
|
|
91
|
+
Utils.toArray(d.passportId, 'utf8'),
|
|
92
|
+
Utils.toArray(d.op, 'utf8'),
|
|
93
|
+
Utils.toArray(d.timestamp, 'utf8'),
|
|
94
|
+
Utils.toArray(d.ownerIdentityKey, 'hex'),
|
|
95
|
+
Utils.toArray(d.actorIdentityKey, 'hex'),
|
|
96
|
+
Utils.toArray(d.actorKeyId, 'utf8'),
|
|
97
|
+
Utils.toArray(d.eventData, 'utf8'),
|
|
98
|
+
Utils.toArray(d.payloadPublic, 'utf8'),
|
|
99
|
+
Utils.toArray(d.payloadOwnerHash, 'hex'),
|
|
100
|
+
outpointFieldBytes(d.lineageGenesis),
|
|
101
|
+
outpointFieldBytes(predecessor),
|
|
102
|
+
Utils.toArray(d.controlLinkage, 'hex'),
|
|
103
|
+
Utils.toArray(d.authorisationCommitment, 'hex'),
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
/** All fields of a state as raw wire bytes: 14 for version 1, 17 for version 2. */
|
|
107
|
+
export function stateToFields(s) {
|
|
108
|
+
const data = s.version === STANDARD_VERSION_V2 ? dataFieldsV2(s) : dataFields(s);
|
|
109
|
+
return [...data, [...s.userSignature], [...s.serverSignature]];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Build the DPP locking script: <33-byte key> OP_CHECKSIG <fields> drops.
|
|
113
|
+
* Custody-neutral (`spec/record-model.md` §2): the locking key may be treasury-derived or user-held.
|
|
114
|
+
* The drop tail is one OP_2DROP per pair of fields and one OP_DROP for an odd
|
|
115
|
+
* field left over: seven OP_2DROP for version 1, eight and an OP_DROP for version 2.
|
|
116
|
+
*/
|
|
117
|
+
export function buildLockingScript(state, lockingPublicKey) {
|
|
118
|
+
const pub = typeof lockingPublicKey === 'string'
|
|
119
|
+
? PublicKey.fromString(lockingPublicKey)
|
|
120
|
+
: lockingPublicKey;
|
|
121
|
+
const pubBytes = pub.encode(true);
|
|
122
|
+
const fields = stateToFields(state);
|
|
123
|
+
const chunks = [
|
|
124
|
+
{ op: pubBytes.length, data: pubBytes },
|
|
125
|
+
{ op: OP.OP_CHECKSIG },
|
|
126
|
+
...fields.map(minimalChunk),
|
|
127
|
+
];
|
|
128
|
+
let undropped = fields.length;
|
|
129
|
+
while (undropped > 1) {
|
|
130
|
+
chunks.push({ op: OP.OP_2DROP });
|
|
131
|
+
undropped -= 2;
|
|
132
|
+
}
|
|
133
|
+
if (undropped !== 0)
|
|
134
|
+
chunks.push({ op: OP.OP_DROP });
|
|
135
|
+
return new LockingScript(chunks);
|
|
136
|
+
}
|
|
137
|
+
const ISO_8601 = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/;
|
|
138
|
+
/**
|
|
139
|
+
* Date.parse refuses most out-of-range components (month 13, hour 25,
|
|
140
|
+
* minute 60) but rolls overflow days forward (2026-02-30 parses as 2 March)
|
|
141
|
+
* and accepts the legacy 24:00 spelling of midnight. The spec demands a real
|
|
142
|
+
* calendar instant: the digits must BE the date they claim.
|
|
143
|
+
*/
|
|
144
|
+
function isRealInstant(match) {
|
|
145
|
+
const [year, month, day, hour] = [match[1], match[2], match[3], match[4]].map(Number);
|
|
146
|
+
if (hour > 23)
|
|
147
|
+
return false;
|
|
148
|
+
const cal = new Date(0);
|
|
149
|
+
cal.setUTCFullYear(year, month - 1, day);
|
|
150
|
+
return (cal.getUTCFullYear() === year &&
|
|
151
|
+
cal.getUTCMonth() === month - 1 &&
|
|
152
|
+
cal.getUTCDate() === day);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Decode a UTF-8 declared field strictly: the bytes must decode and re-encode
|
|
156
|
+
* to themselves. Utils.toUTF8 is lossy (invalid sequences become U+FFFD), so
|
|
157
|
+
* without this check a mangled field slips through decode and only dies at
|
|
158
|
+
* signature verification - and §2 says encoding violations refuse at decode.
|
|
159
|
+
* The round trip is also what lets the signature preimages be recomputed from
|
|
160
|
+
* decoded fields: for accepted states, decoded text and wire bytes are one.
|
|
161
|
+
*/
|
|
162
|
+
function utf8Field(bytes, name) {
|
|
163
|
+
const text = Utils.toUTF8(bytes);
|
|
164
|
+
const roundTrip = Utils.toArray(text, 'utf8');
|
|
165
|
+
if (roundTrip.length !== bytes.length ||
|
|
166
|
+
roundTrip.some((b, i) => b !== bytes[i])) {
|
|
167
|
+
throw new DppFormatError(`${name} must be valid UTF-8`);
|
|
168
|
+
}
|
|
169
|
+
return text;
|
|
170
|
+
}
|
|
171
|
+
function identityKeyHex(bytes, name) {
|
|
172
|
+
if (bytes.length !== 33) {
|
|
173
|
+
throw new DppFormatError(`${name} must be a 33-byte compressed public key`);
|
|
174
|
+
}
|
|
175
|
+
const hex = Utils.toHex(bytes);
|
|
176
|
+
let parsed;
|
|
177
|
+
try {
|
|
178
|
+
parsed = PublicKey.fromString(hex);
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
throw new DppFormatError(`${name} is not a valid public key`);
|
|
182
|
+
}
|
|
183
|
+
// The SDK accepts x >= p by reducing it mod p. Require the canonical SEC1
|
|
184
|
+
// encoding so on-chain bytes are the unique representation of the key.
|
|
185
|
+
if (parsed.toString() !== hex) {
|
|
186
|
+
throw new DppFormatError(`${name} is not a canonical compressed public key`);
|
|
187
|
+
}
|
|
188
|
+
return hex;
|
|
189
|
+
}
|
|
190
|
+
function digestHex(bytes, name) {
|
|
191
|
+
if (bytes.length === 0)
|
|
192
|
+
return '';
|
|
193
|
+
if (bytes.length !== 32) {
|
|
194
|
+
throw new DppFormatError(`${name} must be empty or 32 bytes`);
|
|
195
|
+
}
|
|
196
|
+
return Utils.toHex(bytes);
|
|
197
|
+
}
|
|
198
|
+
/** A version 2 outpoint field: empty, or exactly 36 bytes. */
|
|
199
|
+
function outpointField(bytes, name) {
|
|
200
|
+
if (bytes.length === 0)
|
|
201
|
+
return null;
|
|
202
|
+
if (bytes.length !== OUTPOINT_FIELD_BYTES) {
|
|
203
|
+
throw new DppFormatError(`${name} must be empty or ${OUTPOINT_FIELD_BYTES} bytes`);
|
|
204
|
+
}
|
|
205
|
+
const txid = Utils.toHex(bytes.slice(0, 32));
|
|
206
|
+
const outputIndex = ((bytes[32] << 24) >>> 0) + (bytes[33] << 16) + (bytes[34] << 8) + bytes[35];
|
|
207
|
+
return { txid, outputIndex };
|
|
208
|
+
}
|
|
209
|
+
function requireJson(text, name) {
|
|
210
|
+
try {
|
|
211
|
+
JSON.parse(text);
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
throw new DppFormatError(`${name} must be valid JSON`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function timestampField(bytes) {
|
|
218
|
+
const timestamp = Utils.toUTF8(bytes);
|
|
219
|
+
const isoMatch = ISO_8601.exec(timestamp);
|
|
220
|
+
if (isoMatch == null || Number.isNaN(Date.parse(timestamp))) {
|
|
221
|
+
throw new DppFormatError('timestamp must be ISO 8601');
|
|
222
|
+
}
|
|
223
|
+
if (!isRealInstant(isoMatch)) {
|
|
224
|
+
throw new DppFormatError('timestamp must name a real calendar instant');
|
|
225
|
+
}
|
|
226
|
+
return timestamp;
|
|
227
|
+
}
|
|
228
|
+
/** No field of either version may be the single byte 0x00 (`spec/record-model.md` §2). */
|
|
229
|
+
function refuseLoneNul(fields) {
|
|
230
|
+
// Minimal writing encodes it as OP_0, which reads back as the empty field,
|
|
231
|
+
// so it can only arrive by a non-minimal push; admitting it would give one
|
|
232
|
+
// value two spellings.
|
|
233
|
+
fields.forEach((f, i) => {
|
|
234
|
+
if (f.length === 1 && f[0] === 0) {
|
|
235
|
+
throw new DppFormatError(`field ${i + 1} is the single byte 0x00`);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function passportIdField(bytes) {
|
|
240
|
+
// Bounded in bytes, before decoding: the field is the server signature's
|
|
241
|
+
// BRC-42 key identifier and a wallet refuses one above 800 characters (§3).
|
|
242
|
+
if (bytes.length > MAX_PASSPORT_ID_BYTES) {
|
|
243
|
+
throw new DppFormatError(`passport_id exceeds ${MAX_PASSPORT_ID_BYTES} bytes`);
|
|
244
|
+
}
|
|
245
|
+
const passportId = utf8Field(bytes, 'passport_id');
|
|
246
|
+
if (passportId.length === 0)
|
|
247
|
+
throw new DppFormatError('passport_id must be non-empty');
|
|
248
|
+
return passportId;
|
|
249
|
+
}
|
|
250
|
+
function actorKeyIdField(bytes) {
|
|
251
|
+
// Same reason as passport_id: the user signature's BRC-42 key identifier.
|
|
252
|
+
if (bytes.length > MAX_ACTOR_KEY_ID_BYTES) {
|
|
253
|
+
throw new DppFormatError(`actor_keyID exceeds ${MAX_ACTOR_KEY_ID_BYTES} bytes`);
|
|
254
|
+
}
|
|
255
|
+
const actorKeyId = utf8Field(bytes, 'actor_keyID');
|
|
256
|
+
if (actorKeyId.length === 0)
|
|
257
|
+
throw new DppFormatError('actor_keyID must be non-empty');
|
|
258
|
+
return actorKeyId;
|
|
259
|
+
}
|
|
260
|
+
/** Validate and type raw version 1 fields per `spec/record-model.md` §2-§3. Throws DppFormatError. */
|
|
261
|
+
export function fieldsToState(fields) {
|
|
262
|
+
if (fields.length !== FIELD_COUNT) {
|
|
263
|
+
throw new DppFormatError(`expected ${FIELD_COUNT} fields, found ${fields.length}`);
|
|
264
|
+
}
|
|
265
|
+
refuseLoneNul(fields);
|
|
266
|
+
const marker = Utils.toUTF8(fields[0]);
|
|
267
|
+
if (marker !== PROTOCOL_MARKER) {
|
|
268
|
+
throw new DppFormatError(`protocol_marker must be "${PROTOCOL_MARKER}"`);
|
|
269
|
+
}
|
|
270
|
+
const version = Utils.toUTF8(fields[1]);
|
|
271
|
+
if (version !== STANDARD_VERSION) {
|
|
272
|
+
throw new DppFormatError(version === STANDARD_VERSION_V2
|
|
273
|
+
? `version "${STANDARD_VERSION_V2}" is carried by the ${FIELD_COUNT_V2}-field layout, not the ${FIELD_COUNT}-field one`
|
|
274
|
+
: `unsupported standard version "${version}"`);
|
|
275
|
+
}
|
|
276
|
+
const passportId = passportIdField(fields[2]);
|
|
277
|
+
const op = Utils.toUTF8(fields[3]);
|
|
278
|
+
if (!DPP_OPS.includes(op)) {
|
|
279
|
+
throw new DppFormatError(`unknown op "${op}"`);
|
|
280
|
+
}
|
|
281
|
+
const timestamp = timestampField(fields[4]);
|
|
282
|
+
const ownerIdentityKey = identityKeyHex(fields[5], 'owner_identity_key');
|
|
283
|
+
const actorIdentityKey = identityKeyHex(fields[6], 'actor_identity_key');
|
|
284
|
+
const actorKeyId = actorKeyIdField(fields[7]);
|
|
285
|
+
const eventData = utf8Field(fields[8], 'event_data');
|
|
286
|
+
if (NO_EVENT_OPS.includes(op)) {
|
|
287
|
+
if (eventData !== '') {
|
|
288
|
+
throw new DppFormatError(`event_data must be empty on ${op}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
else if (eventData !== '') {
|
|
292
|
+
requireJson(eventData, 'event_data');
|
|
293
|
+
}
|
|
294
|
+
const payloadPublic = utf8Field(fields[9], 'payload_public');
|
|
295
|
+
if (payloadPublic.length === 0) {
|
|
296
|
+
throw new DppFormatError('payload_public must be present on every state (T2)');
|
|
297
|
+
}
|
|
298
|
+
requireJson(payloadPublic, 'payload_public');
|
|
299
|
+
const payloadOwnerHash = digestHex(fields[10], 'payload_owner_hash');
|
|
300
|
+
const previousTxid = digestHex(fields[11], 'previous_txid');
|
|
301
|
+
const userSignature = fields[12];
|
|
302
|
+
if (userSignature.length === 0)
|
|
303
|
+
throw new DppFormatError('user_signature must be present');
|
|
304
|
+
const serverSignature = fields[13];
|
|
305
|
+
if (serverSignature.length === 0) {
|
|
306
|
+
throw new DppFormatError('server_signature must be present (§3 field 14)');
|
|
307
|
+
}
|
|
308
|
+
return {
|
|
309
|
+
protocolMarker: marker,
|
|
310
|
+
version: '1',
|
|
311
|
+
passportId,
|
|
312
|
+
op,
|
|
313
|
+
timestamp,
|
|
314
|
+
ownerIdentityKey,
|
|
315
|
+
actorIdentityKey,
|
|
316
|
+
actorKeyId,
|
|
317
|
+
eventData,
|
|
318
|
+
payloadPublic,
|
|
319
|
+
payloadOwnerHash,
|
|
320
|
+
previousTxid,
|
|
321
|
+
userSignature,
|
|
322
|
+
serverSignature,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
/** Validate and type raw version 2 fields per `spec/record-model-v2.md` §2-§3. Throws DppFormatError. */
|
|
326
|
+
export function fieldsToStateV2(fields) {
|
|
327
|
+
if (fields.length !== FIELD_COUNT_V2) {
|
|
328
|
+
throw new DppFormatError(`expected ${FIELD_COUNT_V2} fields, found ${fields.length}`);
|
|
329
|
+
}
|
|
330
|
+
refuseLoneNul(fields);
|
|
331
|
+
const marker = Utils.toUTF8(fields[0]);
|
|
332
|
+
if (marker !== PROTOCOL_MARKER) {
|
|
333
|
+
throw new DppFormatError(`protocol_marker must be "${PROTOCOL_MARKER}"`);
|
|
334
|
+
}
|
|
335
|
+
const version = Utils.toUTF8(fields[1]);
|
|
336
|
+
if (version !== STANDARD_VERSION_V2) {
|
|
337
|
+
throw new DppFormatError(version === STANDARD_VERSION
|
|
338
|
+
? `version "${STANDARD_VERSION}" is carried by the ${FIELD_COUNT}-field layout, not the ${FIELD_COUNT_V2}-field one`
|
|
339
|
+
: `unsupported standard version "${version}"`);
|
|
340
|
+
}
|
|
341
|
+
const passportId = passportIdField(fields[2]);
|
|
342
|
+
const op = Utils.toUTF8(fields[3]);
|
|
343
|
+
if (!DPP_OPS_V2.includes(op)) {
|
|
344
|
+
throw new DppFormatError(`unknown op "${op}"`);
|
|
345
|
+
}
|
|
346
|
+
const timestamp = timestampField(fields[4]);
|
|
347
|
+
const ownerIdentityKey = identityKeyHex(fields[5], 'controller_key');
|
|
348
|
+
const actorIdentityKey = identityKeyHex(fields[6], 'actor_identity_key');
|
|
349
|
+
const actorKeyId = actorKeyIdField(fields[7]);
|
|
350
|
+
if (fields[8].length > MAX_EVENT_DATA_BYTES_V2) {
|
|
351
|
+
throw new DppFormatError(`event_data exceeds ${MAX_EVENT_DATA_BYTES_V2} bytes`);
|
|
352
|
+
}
|
|
353
|
+
const eventData = utf8Field(fields[8], 'event_data');
|
|
354
|
+
if (eventData !== '')
|
|
355
|
+
requireJson(eventData, 'event_data');
|
|
356
|
+
if (fields[9].length > MAX_PAYLOAD_PUBLIC_BYTES_V2) {
|
|
357
|
+
throw new DppFormatError(`payload_public exceeds ${MAX_PAYLOAD_PUBLIC_BYTES_V2} bytes`);
|
|
358
|
+
}
|
|
359
|
+
const payloadPublic = utf8Field(fields[9], 'payload_public');
|
|
360
|
+
if (payloadPublic.length === 0) {
|
|
361
|
+
throw new DppFormatError('payload_public must be present on every state');
|
|
362
|
+
}
|
|
363
|
+
requireJson(payloadPublic, 'payload_public');
|
|
364
|
+
const payloadOwnerHash = digestHex(fields[10], 'payload_owner_hash');
|
|
365
|
+
const lineageGenesis = outpointField(fields[11], 'lineage_genesis');
|
|
366
|
+
const predecessor = outpointField(fields[12], 'previous_outpoint');
|
|
367
|
+
const controlLinkage = digestHex(fields[13], 'control_linkage');
|
|
368
|
+
if (op === 'ISSUE' && controlLinkage !== '') {
|
|
369
|
+
throw new DppFormatError('control_linkage must be empty on ISSUE');
|
|
370
|
+
}
|
|
371
|
+
const authorisationCommitment = digestHex(fields[14], 'authorisation_commitment');
|
|
372
|
+
const userSignature = fields[15];
|
|
373
|
+
if (userSignature.length === 0)
|
|
374
|
+
throw new DppFormatError('actor_signature must be present');
|
|
375
|
+
const serverSignature = fields[16];
|
|
376
|
+
if (serverSignature.length === 0)
|
|
377
|
+
throw new DppFormatError('publisher_signature must be present');
|
|
378
|
+
return {
|
|
379
|
+
protocolMarker: marker,
|
|
380
|
+
version: '2',
|
|
381
|
+
passportId,
|
|
382
|
+
op,
|
|
383
|
+
timestamp,
|
|
384
|
+
ownerIdentityKey,
|
|
385
|
+
actorIdentityKey,
|
|
386
|
+
actorKeyId,
|
|
387
|
+
eventData,
|
|
388
|
+
payloadPublic,
|
|
389
|
+
payloadOwnerHash,
|
|
390
|
+
previousTxid: predecessor?.txid ?? '',
|
|
391
|
+
previousOutputIndex: predecessor?.outputIndex ?? null,
|
|
392
|
+
lineageGenesis,
|
|
393
|
+
controlLinkage,
|
|
394
|
+
authorisationCommitment,
|
|
395
|
+
userSignature,
|
|
396
|
+
serverSignature,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Parse a DPP output script of either version. Throws DppFormatError when the
|
|
401
|
+
* script is not a well-formed DPP output: the field count selects the version's
|
|
402
|
+
* rules (fourteen fields for version 1, seventeen for version 2), the version
|
|
403
|
+
* field must agree with the count, and any other count or version is refused by
|
|
404
|
+
* name so an older reader meeting a newer state fails clearly rather than
|
|
405
|
+
* guessing.
|
|
406
|
+
*/
|
|
407
|
+
export function parseDppOutput(script) {
|
|
408
|
+
const chunks = script.chunks;
|
|
409
|
+
if (chunks.length < 2 || chunks[0].data == null || chunks[0].data.length !== 33) {
|
|
410
|
+
throw new DppFormatError('not a DPP output: missing 33-byte locking key push');
|
|
411
|
+
}
|
|
412
|
+
if (chunks[1].op !== OP.OP_CHECKSIG) {
|
|
413
|
+
throw new DppFormatError('not a DPP output: missing OP_CHECKSIG');
|
|
414
|
+
}
|
|
415
|
+
const fields = [];
|
|
416
|
+
let i = 2;
|
|
417
|
+
for (; i < chunks.length; i++) {
|
|
418
|
+
const op = chunks[i].op;
|
|
419
|
+
if (op === OP.OP_2DROP || op === OP.OP_DROP)
|
|
420
|
+
break;
|
|
421
|
+
const field = chunkToField(chunks[i]);
|
|
422
|
+
if (field == null) {
|
|
423
|
+
throw new DppFormatError(`not a DPP output: non-push chunk at index ${i}`);
|
|
424
|
+
}
|
|
425
|
+
fields.push(field);
|
|
426
|
+
}
|
|
427
|
+
if (fields.length !== FIELD_COUNT && fields.length !== FIELD_COUNT_V2) {
|
|
428
|
+
throw new DppFormatError(`expected ${FIELD_COUNT} or ${FIELD_COUNT_V2} fields, found ${fields.length}`);
|
|
429
|
+
}
|
|
430
|
+
const tail = chunks.slice(i);
|
|
431
|
+
const twoDrops = Math.floor(fields.length / 2);
|
|
432
|
+
const oneDrop = fields.length % 2;
|
|
433
|
+
const tailValid = tail.length === twoDrops + oneDrop &&
|
|
434
|
+
tail.slice(0, twoDrops).every((c) => c.op === OP.OP_2DROP && c.data === undefined) &&
|
|
435
|
+
(oneDrop === 0 || (tail[twoDrops].op === OP.OP_DROP && tail[twoDrops].data === undefined));
|
|
436
|
+
if (!tailValid) {
|
|
437
|
+
throw new DppFormatError('not a DPP output: malformed drop tail');
|
|
438
|
+
}
|
|
439
|
+
let lockingPublicKey;
|
|
440
|
+
try {
|
|
441
|
+
lockingPublicKey = PublicKey.fromString(Utils.toHex(chunks[0].data));
|
|
442
|
+
}
|
|
443
|
+
catch {
|
|
444
|
+
// Keep the documented contract: every refusal is a DppFormatError.
|
|
445
|
+
throw new DppFormatError('not a DPP output: locking key is not a valid public key');
|
|
446
|
+
}
|
|
447
|
+
const state = fields.length === FIELD_COUNT_V2 ? fieldsToStateV2(fields) : fieldsToState(fields);
|
|
448
|
+
return { state, lockingPublicKey };
|
|
449
|
+
}
|
|
450
|
+
/** Non-throwing variant of parseDppOutput, for scanning arbitrary outputs. */
|
|
451
|
+
export function tryParseDppOutput(script) {
|
|
452
|
+
try {
|
|
453
|
+
return parseDppOutput(script);
|
|
454
|
+
}
|
|
455
|
+
catch {
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
//# sourceMappingURL=codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAoB,MAAM,UAAU,CAAA;AAChF,OAAO,EACL,OAAO,EACP,UAAU,EACV,WAAW,EACX,cAAc,EACd,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,2BAA2B,EAC3B,YAAY,EACZ,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,gBAAgB,CAAA;AAGvB,qGAAqG;AACrG,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;IAC9B,CAAC;CACF;AAED;;;;GAIG;AACH,SAAS,YAAY,CAAC,IAAc;IAClC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,CAAC,EAAE,CAAA;IACvC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,CAAC,EAAE,CAAA;IACxD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CA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AE,KAAK,EAAE,gBAAgB,EAAE,CAAA;AACpC,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,iBAAiB,CAAC,MAAqB;IAIrD,IAAI,CAAC;QACH,OAAO,cAAc,CAAC,MAAM,CAAC,CAAA;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { WalletProtocol } from '@bsv/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* DPP Token Standard v1 - constants (`spec/record-model.md` §2-§3).
|
|
4
|
+
*
|
|
5
|
+
* Encoding decisions pinned by this reference implementation (the standard
|
|
6
|
+
* fixes field order and semantics; byte encodings are pinned here):
|
|
7
|
+
* - protocol_marker: UTF-8 "dpp"
|
|
8
|
+
* - version: UTF-8 "1"
|
|
9
|
+
* - passport_id, op, timestamp, actor_keyID, event_data, payload_public: UTF-8
|
|
10
|
+
* - owner_identity_key, actor_identity_key: 33-byte compressed public key (raw)
|
|
11
|
+
* - payload_owner_hash: 32-byte SHA-256 digest (raw). Zero-length when absent
|
|
12
|
+
* - previous_txid: 32-byte txid, big-endian display order (raw). Zero-length at genesis
|
|
13
|
+
* - user_signature, server_signature: DER-encoded ECDSA signature
|
|
14
|
+
*
|
|
15
|
+
* Zero-length fields are encoded as OP_0. Within the standard's value domain
|
|
16
|
+
* this is unambiguous: no field may legitimately be the single byte 0x00.
|
|
17
|
+
*/
|
|
18
|
+
export declare const PROTOCOL_MARKER = "dpp";
|
|
19
|
+
export declare const STANDARD_VERSION = "1";
|
|
20
|
+
/**
|
|
21
|
+
* BRC-43 protocol ID under which both token signatures are created, always
|
|
22
|
+
* with counterparty 'anyone' so any third party can derive the verification
|
|
23
|
+
* key from on-chain data alone (§3 fields 7/8, §5).
|
|
24
|
+
* - user_signature: actor identity key + keyID = actor_keyID (field 8)
|
|
25
|
+
* - server_signature: service identity key + keyID = passport_id (field 3)
|
|
26
|
+
*/
|
|
27
|
+
export declare const DPP_PROTOCOL_ID: WalletProtocol;
|
|
28
|
+
/**
|
|
29
|
+
* BRC-43 protocol ID of the owner key (`spec/custody.md` §2, `spec/record-model.md`
|
|
30
|
+
* §3 field 6): field 6 SHOULD be the owner's root derived under this protocol
|
|
31
|
+
* with keyID = passport_id and counterparty 'self', one level, so a BRC-100
|
|
32
|
+
* wallet produces it with getPublicKey and spends a tip locked to it with the
|
|
33
|
+
* PushDrop unlock (`spec/custody.md` §3). 'self' is what makes holdings
|
|
34
|
+
* unlinkable: nobody but the root can compute or confirm the child.
|
|
35
|
+
*/
|
|
36
|
+
export declare const OWNER_PROTOCOL_ID: WalletProtocol;
|
|
37
|
+
/**
|
|
38
|
+
* The event_data property a TRANSFER carries to prove, under the optional
|
|
39
|
+
* owner-signed transfer invariant (`spec/custody.md` §4), that the actor's root
|
|
40
|
+
* derived the previous owner key: the BRC-69 specific key linkage, 64 lower-case
|
|
41
|
+
* hex characters. Reserved on TRANSFER; meaningless elsewhere.
|
|
42
|
+
*/
|
|
43
|
+
export declare const OWNER_LINKAGE_KEY = "owner_linkage";
|
|
44
|
+
/** The one accepted spelling of the linkage scalar: one value, one spelling. */
|
|
45
|
+
export declare const OWNER_LINKAGE_HEX: RegExp;
|
|
46
|
+
/**
|
|
47
|
+
* What a BRC-100 wallet encrypts the linkage under when it reveals it
|
|
48
|
+
* (revealSpecificKeyLinkage: `[2, 'specific linkage revelation <level> <name>']`
|
|
49
|
+
* of the target protocol, keyID = the target keyID, counterparty = the
|
|
50
|
+
* verifier). The verifier decrypts with the prover as counterparty.
|
|
51
|
+
*/
|
|
52
|
+
export declare const OWNER_LINKAGE_REVELATION_PROTOCOL_ID: WalletProtocol;
|
|
53
|
+
/**
|
|
54
|
+
* Upper bounds on the two fields that are also BRC-42 key identifiers
|
|
55
|
+
* (`spec/record-model.md` §3, §5): passport_id keys the server signature,
|
|
56
|
+
* actor_keyID keys the user signature. A conforming wallet refuses a key
|
|
57
|
+
* identifier above 800 characters, so an unbounded field would be a valid
|
|
58
|
+
* record no wallet can sign; the standard bounds them tighter, in bytes of
|
|
59
|
+
* UTF-8, and matches the anchor's subject bound for passport_id.
|
|
60
|
+
*/
|
|
61
|
+
export declare const MAX_PASSPORT_ID_BYTES = 512;
|
|
62
|
+
export declare const MAX_ACTOR_KEY_ID_BYTES = 256;
|
|
63
|
+
/** Total PushDrop fields per state (`spec/record-model.md` §3). */
|
|
64
|
+
export declare const FIELD_COUNT = 14;
|
|
65
|
+
/** Zero-based indices into the 14-field layout. */
|
|
66
|
+
export declare const Field: {
|
|
67
|
+
readonly protocolMarker: 0;
|
|
68
|
+
readonly version: 1;
|
|
69
|
+
readonly passportId: 2;
|
|
70
|
+
readonly op: 3;
|
|
71
|
+
readonly timestamp: 4;
|
|
72
|
+
readonly ownerIdentityKey: 5;
|
|
73
|
+
readonly actorIdentityKey: 6;
|
|
74
|
+
readonly actorKeyId: 7;
|
|
75
|
+
readonly eventData: 8;
|
|
76
|
+
readonly payloadPublic: 9;
|
|
77
|
+
readonly payloadOwnerHash: 10;
|
|
78
|
+
readonly previousTxid: 11;
|
|
79
|
+
readonly userSignature: 12;
|
|
80
|
+
readonly serverSignature: 13;
|
|
81
|
+
};
|
|
82
|
+
export declare const DPP_OPS: readonly ["ACTIVATE", "SOLD", "RESOLD", "REPAIRED", "RECYCLED", "EDIT", "TRANSFER"];
|
|
83
|
+
/** Ops that may change payload_public / payload_owner_hash (§6 invariant 7). */
|
|
84
|
+
export declare const PAYLOAD_CHANGE_OPS: readonly string[];
|
|
85
|
+
/** Ops on which event_data must be the empty string (§3 field 9). */
|
|
86
|
+
export declare const NO_EVENT_OPS: readonly string[];
|
|
87
|
+
/**
|
|
88
|
+
* JSON property inside payload_public carrying the data-carrier reference
|
|
89
|
+
* (chip UID). The lookup service indexes it alongside passport_id, as the
|
|
90
|
+
* `uid` query key in `contracts/overlay.yaml`.
|
|
91
|
+
*/
|
|
92
|
+
export declare const PAYLOAD_DATA_CARRIER_KEY = "dataCarrier";
|
|
93
|
+
export declare const STANDARD_VERSION_V2 = "2";
|
|
94
|
+
/** The record versions a reader of this release decodes; any other value is refused by name. */
|
|
95
|
+
export declare const SUPPORTED_VERSIONS: readonly ["1", "2"];
|
|
96
|
+
export type DppVersion = (typeof SUPPORTED_VERSIONS)[number];
|
|
97
|
+
/**
|
|
98
|
+
* BRC-43 protocol ID of both version 2 record signatures, counterparty
|
|
99
|
+
* 'anyone' as in version 1. Distinct from `DPP_PROTOCOL_ID` so a key derived
|
|
100
|
+
* for one version signs nothing under the other.
|
|
101
|
+
*/
|
|
102
|
+
export declare const DPP_PROTOCOL_ID_V2: WalletProtocol;
|
|
103
|
+
/** Total PushDrop fields per version 2 state. */
|
|
104
|
+
export declare const FIELD_COUNT_V2 = 17;
|
|
105
|
+
/** Zero-based indices into the seventeen-field layout. */
|
|
106
|
+
export declare const FieldV2: {
|
|
107
|
+
readonly protocolMarker: 0;
|
|
108
|
+
readonly version: 1;
|
|
109
|
+
readonly passportId: 2;
|
|
110
|
+
readonly op: 3;
|
|
111
|
+
readonly timestamp: 4;
|
|
112
|
+
readonly controllerKey: 5;
|
|
113
|
+
readonly actorIdentityKey: 6;
|
|
114
|
+
readonly actorKeyId: 7;
|
|
115
|
+
readonly eventData: 8;
|
|
116
|
+
readonly payloadPublic: 9;
|
|
117
|
+
readonly payloadOwnerHash: 10;
|
|
118
|
+
readonly lineageGenesis: 11;
|
|
119
|
+
readonly previousOutpoint: 12;
|
|
120
|
+
readonly controlLinkage: 13;
|
|
121
|
+
readonly authorisationCommitment: 14;
|
|
122
|
+
readonly actorSignature: 15;
|
|
123
|
+
readonly publisherSignature: 16;
|
|
124
|
+
};
|
|
125
|
+
export declare const DPP_OPS_V2: readonly ["ISSUE", "UPDATE", "TRANSFER", "RETIRE"];
|
|
126
|
+
/** Version 2 ops that may change payload_public / payload_owner_hash. RETIRE changes neither. */
|
|
127
|
+
export declare const PAYLOAD_CHANGE_OPS_V2: readonly string[];
|
|
128
|
+
/** Version 2 ops whose actor must prove control of the predecessor. */
|
|
129
|
+
export declare const CONTROL_PROOF_OPS_V2: readonly string[];
|
|
130
|
+
/**
|
|
131
|
+
* The domain tags that open the two version 2 preimages. Each preimage is the
|
|
132
|
+
* tag, then every signed field, each as a Bitcoin VarInt length followed by
|
|
133
|
+
* its bytes (`spec/record-model-v2.md` §5), so the actor preimage and the
|
|
134
|
+
* publisher preimage of one state, and the preimages of any two states,
|
|
135
|
+
* never share bytes by accident.
|
|
136
|
+
*/
|
|
137
|
+
export declare const RECORD_V2_ACTOR_TAG = "dpp-record-v2/actor-signature";
|
|
138
|
+
export declare const RECORD_V2_PUBLISHER_TAG = "dpp-record-v2/publisher-signature";
|
|
139
|
+
/**
|
|
140
|
+
* Byte bounds on the two JSON fields, in UTF-8 bytes (§3). Version 1 left
|
|
141
|
+
* them unbounded; version 2 keeps on-chain data intentional. A profile may
|
|
142
|
+
* bound them tighter, never wider.
|
|
143
|
+
*/
|
|
144
|
+
export declare const MAX_EVENT_DATA_BYTES_V2 = 4096;
|
|
145
|
+
export declare const MAX_PAYLOAD_PUBLIC_BYTES_V2 = 65535;
|
|
146
|
+
/** An outpoint field: the 32-byte txid in display order, then the output index as four big-endian bytes. */
|
|
147
|
+
export declare const OUTPOINT_FIELD_BYTES = 36;
|
|
148
|
+
/** The custody profile Part B delivers: managed custody with explicit recipient acceptance (`spec/managed-custody.md`). */
|
|
149
|
+
export declare const MANAGED_CUSTODY_PROFILE = "managed-custody@1";
|
|
150
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9C;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,eAAe,QAAQ,CAAA;AACpC,eAAO,MAAM,gBAAgB,MAAM,CAAA;AAEnC;;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