@stream44.studio/t44-blockchaincommons.com 0.1.0-rc.2
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/.dco-signatures +9 -0
- package/.github/workflows/dco.yml +12 -0
- package/.github/workflows/gordian-open-integrity.yml +13 -0
- package/.o/GordianOpenIntegrity-CurrentLifehash.svg +1026 -0
- package/.o/GordianOpenIntegrity-InceptionLifehash.svg +1026 -0
- package/.o/GordianOpenIntegrity.yaml +25 -0
- package/DCO.md +34 -0
- package/README.md +210 -0
- package/action.yml +47 -0
- package/bin/oi +152 -0
- package/caps/GordianOpenIntegrity.test.ts +879 -0
- package/caps/GordianOpenIntegrity.ts +821 -0
- package/caps/XidDocumentLedger.test.ts +687 -0
- package/caps/XidDocumentLedger.ts +545 -0
- package/caps/__snapshots__/XidDocumentLedger.test.ts.snap +11 -0
- package/caps/__snapshots__/XidLedger.test.ts.snap +11 -0
- package/caps/lifehash.test.ts +302 -0
- package/caps/lifehash.ts +142 -0
- package/caps/open-integrity-js.test.ts +252 -0
- package/caps/open-integrity-js.ts +485 -0
- package/caps/open-integrity-sh.test.ts +188 -0
- package/caps/open-integrity-sh.ts +187 -0
- package/caps/open-integrity.test.ts +259 -0
- package/caps/provenance-mark-cli.test.ts +387 -0
- package/caps/provenance-mark-cli.ts +174 -0
- package/caps/provenance-mark.test.ts +233 -0
- package/caps/provenance-mark.ts +223 -0
- package/caps/xid.test.ts +828 -0
- package/caps/xid.ts +565 -0
- package/examples/01-XID-DocumentLedger/__snapshots__/main.test.ts.snap +10 -0
- package/examples/01-XID-DocumentLedger/main.test.ts +182 -0
- package/examples/02-XID-Rotate-InceptionKey/__snapshots__/main.test.ts.snap +53 -0
- package/examples/02-XID-Rotate-InceptionKey/main.test.ts +232 -0
- package/examples/03-GordianOpenIntegrity/main.test.ts +176 -0
- package/examples/04-GordianOpenIntegrityCli/main.test.ts +119 -0
- package/package.json +37 -0
- package/tsconfig.json +28 -0
package/caps/xid.ts
ADDED
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
XIDDocument,
|
|
5
|
+
XID,
|
|
6
|
+
Key,
|
|
7
|
+
Delegate,
|
|
8
|
+
Service,
|
|
9
|
+
Privilege,
|
|
10
|
+
XIDPrivateKeyOptions,
|
|
11
|
+
XIDGeneratorOptions,
|
|
12
|
+
XIDVerifySignature,
|
|
13
|
+
} from '@bcts/xid'
|
|
14
|
+
import {
|
|
15
|
+
PrivateKeyBase,
|
|
16
|
+
PublicKeys,
|
|
17
|
+
PrivateKeys,
|
|
18
|
+
} from '@bcts/components'
|
|
19
|
+
import type { ProvenanceMarkResolution } from '@bcts/provenance-mark'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export async function capsule({
|
|
23
|
+
encapsulate,
|
|
24
|
+
CapsulePropertyTypes,
|
|
25
|
+
makeImportStack
|
|
26
|
+
}: {
|
|
27
|
+
encapsulate: any
|
|
28
|
+
CapsulePropertyTypes: any
|
|
29
|
+
makeImportStack: any
|
|
30
|
+
}) {
|
|
31
|
+
|
|
32
|
+
return encapsulate({
|
|
33
|
+
'#@stream44.studio/encapsulate/spine-contracts/CapsuleSpineContract.v0': {
|
|
34
|
+
'#@stream44.studio/encapsulate/structs/Capsule': {},
|
|
35
|
+
'#': {
|
|
36
|
+
|
|
37
|
+
createDocument: {
|
|
38
|
+
type: CapsulePropertyTypes.Function,
|
|
39
|
+
value: async function (this: any, context: {
|
|
40
|
+
keyType?: 'default' | 'publicKeys' | 'privateKeyBase' | 'privateKeys'
|
|
41
|
+
privateKeyBase?: PrivateKeyBase
|
|
42
|
+
publicKeys?: PublicKeys
|
|
43
|
+
privateKeys?: PrivateKeys
|
|
44
|
+
provenance?: {
|
|
45
|
+
type: 'none' | 'passphrase' | 'seed'
|
|
46
|
+
passphrase?: string
|
|
47
|
+
seed?: Uint8Array
|
|
48
|
+
resolution?: ProvenanceMarkResolution
|
|
49
|
+
date?: Date
|
|
50
|
+
}
|
|
51
|
+
}) {
|
|
52
|
+
const keyType = context.keyType || 'default'
|
|
53
|
+
let keyOptions: any = { type: keyType }
|
|
54
|
+
if (keyType === 'publicKeys' && context.publicKeys) {
|
|
55
|
+
keyOptions = { type: 'publicKeys', publicKeys: context.publicKeys }
|
|
56
|
+
} else if (keyType === 'privateKeyBase' && context.privateKeyBase) {
|
|
57
|
+
keyOptions = { type: 'privateKeyBase', privateKeyBase: context.privateKeyBase }
|
|
58
|
+
} else if (keyType === 'privateKeys' && context.privateKeys && context.publicKeys) {
|
|
59
|
+
keyOptions = { type: 'privateKeys', privateKeys: context.privateKeys, publicKeys: context.publicKeys }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let markOptions: any = { type: 'none' }
|
|
63
|
+
if (context.provenance && context.provenance.type !== 'none') {
|
|
64
|
+
markOptions = { ...context.provenance }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return XIDDocument.new(keyOptions, markOptions)
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
getXid: {
|
|
72
|
+
type: CapsulePropertyTypes.Function,
|
|
73
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
74
|
+
return context.document.xid()
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
addResolutionMethod: {
|
|
79
|
+
type: CapsulePropertyTypes.Function,
|
|
80
|
+
value: async function (this: any, context: { document: XIDDocument; method: string }) {
|
|
81
|
+
context.document.addResolutionMethod(context.method)
|
|
82
|
+
return context.document
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
removeResolutionMethod: {
|
|
87
|
+
type: CapsulePropertyTypes.Function,
|
|
88
|
+
value: async function (this: any, context: { document: XIDDocument; method: string }) {
|
|
89
|
+
context.document.removeResolutionMethod(context.method)
|
|
90
|
+
return context.document
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
getResolutionMethods: {
|
|
95
|
+
type: CapsulePropertyTypes.Function,
|
|
96
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
97
|
+
return context.document.resolutionMethods()
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
addKey: {
|
|
102
|
+
type: CapsulePropertyTypes.Function,
|
|
103
|
+
value: async function (this: any, context: {
|
|
104
|
+
document: XIDDocument
|
|
105
|
+
key?: Key
|
|
106
|
+
publicKeys?: PublicKeys
|
|
107
|
+
privateKeyBase?: PrivateKeyBase
|
|
108
|
+
allowAll?: boolean
|
|
109
|
+
}) {
|
|
110
|
+
let key: Key
|
|
111
|
+
if (context.key) {
|
|
112
|
+
key = context.key
|
|
113
|
+
} else if (context.privateKeyBase) {
|
|
114
|
+
key = Key.newWithPrivateKeyBase(context.privateKeyBase)
|
|
115
|
+
} else if (context.publicKeys && context.allowAll) {
|
|
116
|
+
key = Key.newAllowAll(context.publicKeys)
|
|
117
|
+
} else if (context.publicKeys) {
|
|
118
|
+
key = Key.new(context.publicKeys)
|
|
119
|
+
} else {
|
|
120
|
+
throw new Error('Must provide key, publicKeys, or privateKeyBase')
|
|
121
|
+
}
|
|
122
|
+
context.document.addKey(key)
|
|
123
|
+
return { document: context.document, key }
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
getKeys: {
|
|
128
|
+
type: CapsulePropertyTypes.Function,
|
|
129
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
130
|
+
return context.document.keys()
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
findKeyByPublicKeys: {
|
|
135
|
+
type: CapsulePropertyTypes.Function,
|
|
136
|
+
value: async function (this: any, context: { document: XIDDocument; publicKeys: PublicKeys }) {
|
|
137
|
+
return context.document.findKeyByPublicKeys(context.publicKeys)
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
removeKey: {
|
|
142
|
+
type: CapsulePropertyTypes.Function,
|
|
143
|
+
value: async function (this: any, context: { document: XIDDocument; publicKeys: PublicKeys }) {
|
|
144
|
+
context.document.removeKey(context.publicKeys)
|
|
145
|
+
return context.document
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
getInceptionKey: {
|
|
150
|
+
type: CapsulePropertyTypes.Function,
|
|
151
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
152
|
+
return context.document.inceptionKey()
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
removeInceptionKey: {
|
|
157
|
+
type: CapsulePropertyTypes.Function,
|
|
158
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
159
|
+
const removed = context.document.removeInceptionKey()
|
|
160
|
+
return { document: context.document, removedKey: removed }
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
isInceptionSigningKey: {
|
|
165
|
+
type: CapsulePropertyTypes.Function,
|
|
166
|
+
value: async function (this: any, context: { document: XIDDocument; signingPublicKey: any }) {
|
|
167
|
+
return context.document.isInceptionSigningKey(context.signingPublicKey)
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
setKeyNickname: {
|
|
172
|
+
type: CapsulePropertyTypes.Function,
|
|
173
|
+
value: async function (this: any, context: { document: XIDDocument; publicKeys: PublicKeys; name: string }) {
|
|
174
|
+
context.document.setNameForKey(context.publicKeys, context.name)
|
|
175
|
+
return context.document
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
setKeyPermissions: {
|
|
180
|
+
type: CapsulePropertyTypes.Function,
|
|
181
|
+
value: async function (this: any, context: {
|
|
182
|
+
key: Key
|
|
183
|
+
allow?: Privilege[]
|
|
184
|
+
deny?: Privilege[]
|
|
185
|
+
}) {
|
|
186
|
+
if (context.allow) {
|
|
187
|
+
for (const p of context.allow) {
|
|
188
|
+
context.key.permissions().addAllow(p)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (context.deny) {
|
|
192
|
+
for (const p of context.deny) {
|
|
193
|
+
context.key.permissions().addDeny(p)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return context.key
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
addKeyEndpoint: {
|
|
201
|
+
type: CapsulePropertyTypes.Function,
|
|
202
|
+
value: async function (this: any, context: { key: Key; endpoint: string }) {
|
|
203
|
+
context.key.addEndpoint(context.endpoint)
|
|
204
|
+
return context.key
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
addDelegate: {
|
|
209
|
+
type: CapsulePropertyTypes.Function,
|
|
210
|
+
value: async function (this: any, context: {
|
|
211
|
+
document: XIDDocument
|
|
212
|
+
delegateDocument: XIDDocument
|
|
213
|
+
allow?: Privilege[]
|
|
214
|
+
deny?: Privilege[]
|
|
215
|
+
}) {
|
|
216
|
+
const delegate = Delegate.new(context.delegateDocument)
|
|
217
|
+
if (context.allow) {
|
|
218
|
+
for (const p of context.allow) {
|
|
219
|
+
delegate.permissions().addAllow(p)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (context.deny) {
|
|
223
|
+
for (const p of context.deny) {
|
|
224
|
+
delegate.permissions().addDeny(p)
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
context.document.addDelegate(delegate)
|
|
228
|
+
return { document: context.document, delegate }
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
|
|
232
|
+
getDelegates: {
|
|
233
|
+
type: CapsulePropertyTypes.Function,
|
|
234
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
235
|
+
return context.document.delegates()
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
findDelegateByXid: {
|
|
240
|
+
type: CapsulePropertyTypes.Function,
|
|
241
|
+
value: async function (this: any, context: { document: XIDDocument; xid: XID }) {
|
|
242
|
+
return context.document.findDelegateByXid(context.xid)
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
removeDelegate: {
|
|
247
|
+
type: CapsulePropertyTypes.Function,
|
|
248
|
+
value: async function (this: any, context: { document: XIDDocument; xid: XID }) {
|
|
249
|
+
context.document.removeDelegate(context.xid)
|
|
250
|
+
return context.document
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
|
|
254
|
+
addService: {
|
|
255
|
+
type: CapsulePropertyTypes.Function,
|
|
256
|
+
value: async function (this: any, context: {
|
|
257
|
+
document: XIDDocument
|
|
258
|
+
uri: string
|
|
259
|
+
name?: string
|
|
260
|
+
capability?: string
|
|
261
|
+
keyReferences?: any[]
|
|
262
|
+
delegateReferences?: any[]
|
|
263
|
+
allow?: Privilege[]
|
|
264
|
+
}) {
|
|
265
|
+
const service = Service.new(context.uri)
|
|
266
|
+
if (context.name) {
|
|
267
|
+
service.setName(context.name)
|
|
268
|
+
}
|
|
269
|
+
if (context.capability) {
|
|
270
|
+
service.addCapability(context.capability)
|
|
271
|
+
}
|
|
272
|
+
if (context.keyReferences) {
|
|
273
|
+
for (const ref of context.keyReferences) {
|
|
274
|
+
service.addKeyReference(ref)
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (context.delegateReferences) {
|
|
278
|
+
for (const ref of context.delegateReferences) {
|
|
279
|
+
service.addDelegateReference(ref)
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (context.allow) {
|
|
283
|
+
for (const p of context.allow) {
|
|
284
|
+
service.permissions().addAllow(p)
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
context.document.addService(service)
|
|
288
|
+
return { document: context.document, service }
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
|
|
292
|
+
getServices: {
|
|
293
|
+
type: CapsulePropertyTypes.Function,
|
|
294
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
295
|
+
return context.document.services()
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
findServiceByUri: {
|
|
300
|
+
type: CapsulePropertyTypes.Function,
|
|
301
|
+
value: async function (this: any, context: { document: XIDDocument; uri: string }) {
|
|
302
|
+
return context.document.findServiceByUri(context.uri)
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
|
|
306
|
+
removeService: {
|
|
307
|
+
type: CapsulePropertyTypes.Function,
|
|
308
|
+
value: async function (this: any, context: { document: XIDDocument; uri: string }) {
|
|
309
|
+
context.document.removeService(context.uri)
|
|
310
|
+
return context.document
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
|
|
314
|
+
getProvenance: {
|
|
315
|
+
type: CapsulePropertyTypes.Function,
|
|
316
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
317
|
+
return {
|
|
318
|
+
mark: context.document.provenance(),
|
|
319
|
+
generator: context.document.provenanceGenerator()
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
|
|
324
|
+
advanceProvenance: {
|
|
325
|
+
type: CapsulePropertyTypes.Function,
|
|
326
|
+
value: async function (this: any, context: {
|
|
327
|
+
document: XIDDocument
|
|
328
|
+
password?: Uint8Array
|
|
329
|
+
date?: Date
|
|
330
|
+
}) {
|
|
331
|
+
context.document.nextProvenanceMarkWithEmbeddedGenerator(
|
|
332
|
+
context.password,
|
|
333
|
+
context.date
|
|
334
|
+
)
|
|
335
|
+
return context.document
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
|
|
339
|
+
toEnvelope: {
|
|
340
|
+
type: CapsulePropertyTypes.Function,
|
|
341
|
+
value: async function (this: any, context: {
|
|
342
|
+
document: XIDDocument
|
|
343
|
+
privateKeyOptions?: any
|
|
344
|
+
generatorOptions?: any
|
|
345
|
+
signingOptions?: any
|
|
346
|
+
}) {
|
|
347
|
+
return context.document.toEnvelope(
|
|
348
|
+
context.privateKeyOptions ?? XIDPrivateKeyOptions.Omit,
|
|
349
|
+
context.generatorOptions ?? XIDGeneratorOptions.Omit,
|
|
350
|
+
context.signingOptions ?? { type: 'none' }
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
|
|
355
|
+
fromEnvelope: {
|
|
356
|
+
type: CapsulePropertyTypes.Function,
|
|
357
|
+
value: async function (this: any, context: {
|
|
358
|
+
envelope: any
|
|
359
|
+
password?: Uint8Array
|
|
360
|
+
verifySignature?: XIDVerifySignature
|
|
361
|
+
}) {
|
|
362
|
+
return XIDDocument.fromEnvelope(
|
|
363
|
+
context.envelope,
|
|
364
|
+
context.password,
|
|
365
|
+
context.verifySignature ?? XIDVerifySignature.None
|
|
366
|
+
)
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
|
|
370
|
+
toSignedEnvelope: {
|
|
371
|
+
type: CapsulePropertyTypes.Function,
|
|
372
|
+
value: async function (this: any, context: {
|
|
373
|
+
document: XIDDocument
|
|
374
|
+
signingKey: any
|
|
375
|
+
privateKeyOptions?: any
|
|
376
|
+
}) {
|
|
377
|
+
return context.document.toSignedEnvelopeOpt(
|
|
378
|
+
context.signingKey,
|
|
379
|
+
context.privateKeyOptions ?? XIDPrivateKeyOptions.Omit
|
|
380
|
+
)
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
|
|
384
|
+
addAttachment: {
|
|
385
|
+
type: CapsulePropertyTypes.Function,
|
|
386
|
+
value: async function (this: any, context: {
|
|
387
|
+
document: XIDDocument
|
|
388
|
+
payload: any
|
|
389
|
+
vendor: string
|
|
390
|
+
conformsTo?: string
|
|
391
|
+
}) {
|
|
392
|
+
context.document.addAttachment(context.payload, context.vendor, context.conformsTo)
|
|
393
|
+
return context.document
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
|
|
397
|
+
hasAttachments: {
|
|
398
|
+
type: CapsulePropertyTypes.Function,
|
|
399
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
400
|
+
return context.document.hasAttachments()
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
|
|
404
|
+
clearAttachments: {
|
|
405
|
+
type: CapsulePropertyTypes.Function,
|
|
406
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
407
|
+
context.document.clearAttachments()
|
|
408
|
+
return context.document
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
|
|
412
|
+
cloneDocument: {
|
|
413
|
+
type: CapsulePropertyTypes.Function,
|
|
414
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
415
|
+
return context.document.clone()
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
|
|
419
|
+
getEncryptionKey: {
|
|
420
|
+
type: CapsulePropertyTypes.Function,
|
|
421
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
422
|
+
return context.document.encryptionKey()
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
|
|
426
|
+
getVerificationKey: {
|
|
427
|
+
type: CapsulePropertyTypes.Function,
|
|
428
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
429
|
+
return context.document.verificationKey()
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
|
|
433
|
+
getReference: {
|
|
434
|
+
type: CapsulePropertyTypes.Function,
|
|
435
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
436
|
+
return context.document.reference()
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
|
|
440
|
+
isEmpty: {
|
|
441
|
+
type: CapsulePropertyTypes.Function,
|
|
442
|
+
value: async function (this: any, context: { document: XIDDocument }) {
|
|
443
|
+
return context.document.isEmpty()
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
|
|
447
|
+
equals: {
|
|
448
|
+
type: CapsulePropertyTypes.Function,
|
|
449
|
+
value: async function (this: any, context: { document: XIDDocument; other: XIDDocument }) {
|
|
450
|
+
return context.document.equals(context.other)
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
|
|
454
|
+
getPrivateKeyEnvelope: {
|
|
455
|
+
type: CapsulePropertyTypes.Function,
|
|
456
|
+
value: async function (this: any, context: {
|
|
457
|
+
document: XIDDocument
|
|
458
|
+
publicKeys: PublicKeys
|
|
459
|
+
password?: string
|
|
460
|
+
}) {
|
|
461
|
+
return context.document.privateKeyEnvelopeForKey(context.publicKeys, context.password)
|
|
462
|
+
}
|
|
463
|
+
},
|
|
464
|
+
|
|
465
|
+
addEnvelopeAssertion: {
|
|
466
|
+
type: CapsulePropertyTypes.Function,
|
|
467
|
+
value: async function (this: any, context: {
|
|
468
|
+
envelope: any
|
|
469
|
+
predicate: string
|
|
470
|
+
object: string
|
|
471
|
+
}) {
|
|
472
|
+
return context.envelope.addAssertion(context.predicate, context.object)
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
|
|
476
|
+
getEnvelopeAssertions: {
|
|
477
|
+
type: CapsulePropertyTypes.Function,
|
|
478
|
+
value: async function (this: any, context: {
|
|
479
|
+
envelope: any
|
|
480
|
+
predicate: string
|
|
481
|
+
}): Promise<string[]> {
|
|
482
|
+
const assertions = context.envelope.assertionsWithPredicate(context.predicate)
|
|
483
|
+
return assertions.map((a: any) => {
|
|
484
|
+
const obj = a.subject().asObject()
|
|
485
|
+
return obj ? (obj.asText?.() ?? obj.format?.() ?? '') : ''
|
|
486
|
+
}).filter((s: string) => s !== '')
|
|
487
|
+
}
|
|
488
|
+
},
|
|
489
|
+
|
|
490
|
+
envelopeToUrString: {
|
|
491
|
+
type: CapsulePropertyTypes.Function,
|
|
492
|
+
value: async function (this: any, context: { envelope: any }) {
|
|
493
|
+
return context.envelope.urString()
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
|
|
497
|
+
envelopeFromUrString: {
|
|
498
|
+
type: CapsulePropertyTypes.Function,
|
|
499
|
+
value: async function (this: any, context: { urString: string }) {
|
|
500
|
+
// Get Envelope class from a temporary document's envelope
|
|
501
|
+
const tmpDoc = XIDDocument.new({ type: 'default' }, { type: 'none' })
|
|
502
|
+
const tmpEnvelope = tmpDoc.toEnvelope()
|
|
503
|
+
const EnvelopeClass = tmpEnvelope.constructor as any
|
|
504
|
+
return EnvelopeClass.fromUrString(context.urString)
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
|
|
508
|
+
toDocumentUrString: {
|
|
509
|
+
type: CapsulePropertyTypes.Function,
|
|
510
|
+
value: async function (this: any, context: {
|
|
511
|
+
document: XIDDocument
|
|
512
|
+
privateKeyOptions?: any
|
|
513
|
+
generatorOptions?: any
|
|
514
|
+
}) {
|
|
515
|
+
const envelope = context.document.toEnvelope(
|
|
516
|
+
context.privateKeyOptions ?? XIDPrivateKeyOptions.Omit,
|
|
517
|
+
context.generatorOptions ?? XIDGeneratorOptions.Omit,
|
|
518
|
+
{ type: 'none' }
|
|
519
|
+
)
|
|
520
|
+
return envelope.urString()
|
|
521
|
+
}
|
|
522
|
+
},
|
|
523
|
+
|
|
524
|
+
fromDocumentUrString: {
|
|
525
|
+
type: CapsulePropertyTypes.Function,
|
|
526
|
+
value: async function (this: any, context: {
|
|
527
|
+
urString: string
|
|
528
|
+
password?: Uint8Array
|
|
529
|
+
}) {
|
|
530
|
+
const tmpDoc = XIDDocument.new({ type: 'default' }, { type: 'none' })
|
|
531
|
+
const tmpEnvelope = tmpDoc.toEnvelope()
|
|
532
|
+
const EnvelopeClass = tmpEnvelope.constructor as any
|
|
533
|
+
const envelope = EnvelopeClass.fromUrString(context.urString)
|
|
534
|
+
return XIDDocument.fromEnvelope(envelope, context.password, XIDVerifySignature.None)
|
|
535
|
+
}
|
|
536
|
+
},
|
|
537
|
+
|
|
538
|
+
// Expose library types for convenience
|
|
539
|
+
types: {
|
|
540
|
+
type: CapsulePropertyTypes.Function,
|
|
541
|
+
value: async function (this: any) {
|
|
542
|
+
return {
|
|
543
|
+
XIDDocument,
|
|
544
|
+
XID,
|
|
545
|
+
Key,
|
|
546
|
+
Delegate,
|
|
547
|
+
Service,
|
|
548
|
+
Privilege,
|
|
549
|
+
XIDPrivateKeyOptions,
|
|
550
|
+
XIDGeneratorOptions,
|
|
551
|
+
XIDVerifySignature,
|
|
552
|
+
PrivateKeyBase,
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}, {
|
|
560
|
+
importMeta: import.meta,
|
|
561
|
+
importStack: makeImportStack(),
|
|
562
|
+
capsuleName: capsule['#'],
|
|
563
|
+
})
|
|
564
|
+
}
|
|
565
|
+
capsule['#'] = 't44/caps/providers/blockchaincommons.com/xid'
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Bun Snapshot v1, https://bun.sh/docs/test/snapshots
|
|
2
|
+
|
|
3
|
+
exports[`XID Ledger 5. Summary should match the ledger summary snapshot 1`] = `
|
|
4
|
+
"XID Ledger (3 revisions)
|
|
5
|
+
XID: XID(5574aeaf)
|
|
6
|
+
|
|
7
|
+
#0 [c2a54b58] 2025-01-01T00:00:00Z "genesis"
|
|
8
|
+
#1 [ea3da3a2] 2025-01-02T00:00:00Z "add-second-key"
|
|
9
|
+
#2 [7a00c8ef] 2025-01-03T00:00:00Z "add-third-key""
|
|
10
|
+
`;
|