@ckb-ccc/did-ckb 0.2.14 → 0.2.16
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/CHANGELOG.md +17 -0
- package/dist/barrel-BYdcNWd1.d.mts +431 -0
- package/dist/barrel-BYdcNWd1.d.mts.map +1 -0
- package/dist/barrel-CRigE_Kq.mjs +2 -0
- package/dist/barrel-CRigE_Kq.mjs.map +1 -0
- package/dist/barrel.d.mts +3 -440
- package/dist/barrel.mjs +1 -1
- package/{dist.commonjs/index-DbyAhugH.d.ts → dist/index-C0QY5P5_.d.mts} +2 -3
- package/dist/{index-PkKhX08A.d.mts.map → index-C0QY5P5_.d.mts.map} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/plc-CAHX4f5y.mjs +2 -0
- package/dist/plc-CAHX4f5y.mjs.map +1 -0
- package/dist/plc.d.mts +1 -1
- package/dist/plc.mjs +1 -2
- package/dist/rolldown-runtime-P3Pd_6ND.mjs +1 -0
- package/dist.commonjs/barrel-9fYvfkI1.d.ts +431 -0
- package/dist.commonjs/barrel-9fYvfkI1.d.ts.map +1 -0
- package/dist.commonjs/barrel-BWApUcdp.js +6 -0
- package/dist.commonjs/barrel-BWApUcdp.js.map +1 -0
- package/dist.commonjs/barrel.d.ts +3 -440
- package/dist.commonjs/barrel.js +1 -1
- package/{dist/index-PkKhX08A.d.mts → dist.commonjs/index-C0QY5P5_.d.ts} +1 -2
- package/dist.commonjs/{index-DbyAhugH.d.ts.map → index-C0QY5P5_.d.ts.map} +1 -1
- package/dist.commonjs/index.d.ts +2 -2
- package/dist.commonjs/index.js +1 -1
- package/dist.commonjs/plc-DMi9GhTp.js +2 -0
- package/dist.commonjs/{plc.js.map → plc-DMi9GhTp.js.map} +1 -1
- package/dist.commonjs/plc.d.ts +1 -1
- package/dist.commonjs/plc.js +1 -2
- package/package.json +3 -3
- package/src/history.ts +4 -8
- package/dist/barrel-DEJnxd4o.mjs +0 -2
- package/dist/barrel-DEJnxd4o.mjs.map +0 -1
- package/dist/barrel.d.mts.map +0 -1
- package/dist/plc.mjs.map +0 -1
- package/dist/rolldown-runtime-DK3Fl9T5.mjs +0 -1
- package/dist.commonjs/barrel-C62ZxemC.js +0 -2
- package/dist.commonjs/barrel-C62ZxemC.js.map +0 -1
- package/dist.commonjs/barrel.d.ts.map +0 -1
- package/dist.commonjs/rolldown-runtime-BIInC43l.js +0 -1
|
@@ -1,440 +1,3 @@
|
|
|
1
|
-
import { d as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export type DidCkbDataV1Like = {
|
|
5
|
-
document: unknown;
|
|
6
|
-
localId?: string | null;
|
|
7
|
-
};
|
|
8
|
-
declare const DidCkbDataV1_base: (abstract new () => {
|
|
9
|
-
toBytes(): ccc.Bytes;
|
|
10
|
-
clone(): DidCkbDataV1;
|
|
11
|
-
eq(other: DidCkbDataV1Like): boolean;
|
|
12
|
-
hash(): ccc.Hex;
|
|
13
|
-
toHex(): ccc.Hex;
|
|
14
|
-
}) & {
|
|
15
|
-
byteLength?: number;
|
|
16
|
-
encode(_: DidCkbDataV1Like): ccc.Bytes;
|
|
17
|
-
decode(_: ccc.BytesLike): DidCkbDataV1;
|
|
18
|
-
fromBytes(_bytes: ccc.BytesLike): DidCkbDataV1;
|
|
19
|
-
from(_: DidCkbDataV1Like): DidCkbDataV1;
|
|
20
|
-
Base<SubTypeLike, SubType = SubTypeLike>(): any;
|
|
21
|
-
BaseUnion<CodecType extends ccc.CodecLike<any, ccc.mol.UnionDecoded<any, any>>, SubTypeLike_1, SubType_1 = SubTypeLike_1>(): (abstract new (inner: ccc.DecodedType<CodecType>) => {
|
|
22
|
-
readonly inner: ccc.DecodedType<CodecType>;
|
|
23
|
-
match<Result>(handlers: ccc.mol.UnionMatchHandlers<CodecType, Result> & {
|
|
24
|
-
_?: undefined | null;
|
|
25
|
-
}): Result;
|
|
26
|
-
match<Result>(handlers: Partial<ccc.mol.UnionMatchHandlers<CodecType, Result>> & {
|
|
27
|
-
_: (inner: ccc.DecodedType<CodecType>) => Result;
|
|
28
|
-
}): Result;
|
|
29
|
-
toBytes(): ccc.Bytes;
|
|
30
|
-
clone(): SubType_1;
|
|
31
|
-
eq(other: SubTypeLike_1): boolean;
|
|
32
|
-
hash(): ccc.Hex;
|
|
33
|
-
toHex(): ccc.Hex;
|
|
34
|
-
}) & {
|
|
35
|
-
byteLength?: number;
|
|
36
|
-
encode(_: SubTypeLike_1): ccc.Bytes;
|
|
37
|
-
decode(_: ccc.BytesLike): SubType_1;
|
|
38
|
-
fromBytes(_bytes: ccc.BytesLike): SubType_1;
|
|
39
|
-
from(_: SubTypeLike_1): SubType_1;
|
|
40
|
-
Base<SubTypeLike, SubType = SubTypeLike>(): any;
|
|
41
|
-
BaseUnion<CodecType_1 extends ccc.CodecLike<any, ccc.mol.UnionDecoded<any, any>>, SubTypeLike_1_1, SubType_1_1 = SubTypeLike_1_1>(): any;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
export declare class DidCkbDataV1 extends DidCkbDataV1_base {
|
|
45
|
-
document: unknown;
|
|
46
|
-
localId?: string | undefined;
|
|
47
|
-
constructor(document: unknown, localId?: string | undefined);
|
|
48
|
-
static from(data: DidCkbDataV1Like): DidCkbDataV1;
|
|
49
|
-
}
|
|
50
|
-
export type DidCkbDataLike = {
|
|
51
|
-
type?: "v1" | null;
|
|
52
|
-
value: DidCkbDataV1Like;
|
|
53
|
-
} | {
|
|
54
|
-
inner: {
|
|
55
|
-
type?: "v1" | null;
|
|
56
|
-
value: DidCkbDataV1Like;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
declare const DidCkbData_base: (abstract new (inner: {
|
|
60
|
-
type: "v1";
|
|
61
|
-
value: DidCkbDataV1;
|
|
62
|
-
}) => {
|
|
63
|
-
readonly inner: {
|
|
64
|
-
type: "v1";
|
|
65
|
-
value: DidCkbDataV1;
|
|
66
|
-
};
|
|
67
|
-
match<Result>(handlers: ccc.mol.UnionMatchHandlers<ccc.Codec<{
|
|
68
|
-
type: "v1";
|
|
69
|
-
value: DidCkbDataV1Like;
|
|
70
|
-
} | {
|
|
71
|
-
inner: {
|
|
72
|
-
type: "v1";
|
|
73
|
-
value: DidCkbDataV1Like;
|
|
74
|
-
};
|
|
75
|
-
}, {
|
|
76
|
-
type: "v1";
|
|
77
|
-
value: DidCkbDataV1;
|
|
78
|
-
}>, Result> & {
|
|
79
|
-
_?: undefined | null;
|
|
80
|
-
}): Result;
|
|
81
|
-
match<Result>(handlers: Partial<ccc.mol.UnionMatchHandlers<ccc.Codec<{
|
|
82
|
-
type: "v1";
|
|
83
|
-
value: DidCkbDataV1Like;
|
|
84
|
-
} | {
|
|
85
|
-
inner: {
|
|
86
|
-
type: "v1";
|
|
87
|
-
value: DidCkbDataV1Like;
|
|
88
|
-
};
|
|
89
|
-
}, {
|
|
90
|
-
type: "v1";
|
|
91
|
-
value: DidCkbDataV1;
|
|
92
|
-
}>, Result>> & {
|
|
93
|
-
_: (inner: {
|
|
94
|
-
type: "v1";
|
|
95
|
-
value: DidCkbDataV1;
|
|
96
|
-
}) => Result;
|
|
97
|
-
}): Result;
|
|
98
|
-
toBytes(): ccc.Bytes;
|
|
99
|
-
clone(): DidCkbData;
|
|
100
|
-
eq(other: DidCkbDataLike): boolean;
|
|
101
|
-
hash(): ccc.Hex;
|
|
102
|
-
toHex(): ccc.Hex;
|
|
103
|
-
}) & {
|
|
104
|
-
byteLength?: number;
|
|
105
|
-
encode(_: DidCkbDataLike): ccc.Bytes;
|
|
106
|
-
decode(_: ccc.BytesLike): DidCkbData;
|
|
107
|
-
fromBytes(_bytes: ccc.BytesLike): DidCkbData;
|
|
108
|
-
from(_: DidCkbDataLike): DidCkbData;
|
|
109
|
-
Base<SubTypeLike_1, SubType_1 = SubTypeLike_1>(): (abstract new () => {
|
|
110
|
-
toBytes(): ccc.Bytes;
|
|
111
|
-
clone(): SubType_1;
|
|
112
|
-
eq(other: SubTypeLike_1): boolean;
|
|
113
|
-
hash(): ccc.Hex;
|
|
114
|
-
toHex(): ccc.Hex;
|
|
115
|
-
}) & {
|
|
116
|
-
byteLength?: number;
|
|
117
|
-
encode(_: SubTypeLike_1): ccc.Bytes;
|
|
118
|
-
decode(_: ccc.BytesLike): SubType_1;
|
|
119
|
-
fromBytes(_bytes: ccc.BytesLike): SubType_1;
|
|
120
|
-
from(_: SubTypeLike_1): SubType_1;
|
|
121
|
-
Base<SubTypeLike_1_1, SubType_1_1 = SubTypeLike_1_1>(): any;
|
|
122
|
-
BaseUnion<CodecType extends ccc.CodecLike<any, ccc.mol.UnionDecoded<any, any>>, SubTypeLike, SubType = SubTypeLike>(): any;
|
|
123
|
-
};
|
|
124
|
-
BaseUnion<CodecType extends ccc.CodecLike<any, ccc.mol.UnionDecoded<any, any>>, SubTypeLike, SubType = SubTypeLike>(): any;
|
|
125
|
-
};
|
|
126
|
-
export declare class DidCkbData extends DidCkbData_base {
|
|
127
|
-
type: "v1";
|
|
128
|
-
value: DidCkbDataV1;
|
|
129
|
-
constructor(type: "v1", value: DidCkbDataV1);
|
|
130
|
-
static from(data: DidCkbDataLike): DidCkbData;
|
|
131
|
-
static fromV1(data: DidCkbDataV1Like): DidCkbData & {
|
|
132
|
-
type: "v1";
|
|
133
|
-
value: DidCkbDataV1;
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
export type PlcAuthorizationLike = {
|
|
137
|
-
history: object[];
|
|
138
|
-
sig: ccc.HexLike;
|
|
139
|
-
rotationKeyIndices: ccc.NumLike[];
|
|
140
|
-
};
|
|
141
|
-
declare const PlcAuthorization_base: (abstract new () => {
|
|
142
|
-
toBytes(): ccc.Bytes;
|
|
143
|
-
clone(): PlcAuthorization;
|
|
144
|
-
eq(other: PlcAuthorizationLike): boolean;
|
|
145
|
-
hash(): ccc.Hex;
|
|
146
|
-
toHex(): ccc.Hex;
|
|
147
|
-
}) & {
|
|
148
|
-
byteLength?: number;
|
|
149
|
-
encode(_: PlcAuthorizationLike): ccc.Bytes;
|
|
150
|
-
decode(_: ccc.BytesLike): PlcAuthorization;
|
|
151
|
-
fromBytes(_bytes: ccc.BytesLike): PlcAuthorization;
|
|
152
|
-
from(_: PlcAuthorizationLike): PlcAuthorization;
|
|
153
|
-
Base<SubTypeLike, SubType = SubTypeLike>(): any;
|
|
154
|
-
BaseUnion<CodecType extends ccc.CodecLike<any, ccc.mol.UnionDecoded<any, any>>, SubTypeLike_1, SubType_1 = SubTypeLike_1>(): (abstract new (inner: ccc.DecodedType<CodecType>) => {
|
|
155
|
-
readonly inner: ccc.DecodedType<CodecType>;
|
|
156
|
-
match<Result>(handlers: ccc.mol.UnionMatchHandlers<CodecType, Result> & {
|
|
157
|
-
_?: undefined | null;
|
|
158
|
-
}): Result;
|
|
159
|
-
match<Result>(handlers: Partial<ccc.mol.UnionMatchHandlers<CodecType, Result>> & {
|
|
160
|
-
_: (inner: ccc.DecodedType<CodecType>) => Result;
|
|
161
|
-
}): Result;
|
|
162
|
-
toBytes(): ccc.Bytes;
|
|
163
|
-
clone(): SubType_1;
|
|
164
|
-
eq(other: SubTypeLike_1): boolean;
|
|
165
|
-
hash(): ccc.Hex;
|
|
166
|
-
toHex(): ccc.Hex;
|
|
167
|
-
}) & {
|
|
168
|
-
byteLength?: number;
|
|
169
|
-
encode(_: SubTypeLike_1): ccc.Bytes;
|
|
170
|
-
decode(_: ccc.BytesLike): SubType_1;
|
|
171
|
-
fromBytes(_bytes: ccc.BytesLike): SubType_1;
|
|
172
|
-
from(_: SubTypeLike_1): SubType_1;
|
|
173
|
-
Base<SubTypeLike, SubType = SubTypeLike>(): any;
|
|
174
|
-
BaseUnion<CodecType_1 extends ccc.CodecLike<any, ccc.mol.UnionDecoded<any, any>>, SubTypeLike_1_1, SubType_1_1 = SubTypeLike_1_1>(): any;
|
|
175
|
-
};
|
|
176
|
-
};
|
|
177
|
-
export declare class PlcAuthorization extends PlcAuthorization_base {
|
|
178
|
-
history: object[];
|
|
179
|
-
sig: ccc.Hex;
|
|
180
|
-
rotationKeyIndices: ccc.Num[];
|
|
181
|
-
constructor(history: object[], sig: ccc.Hex, rotationKeyIndices: ccc.Num[]);
|
|
182
|
-
static from(data: PlcAuthorizationLike): PlcAuthorization;
|
|
183
|
-
}
|
|
184
|
-
export type DidCkbWitnessLike = {
|
|
185
|
-
localIdAuthorization: PlcAuthorizationLike;
|
|
186
|
-
};
|
|
187
|
-
declare const DidCkbWitness_base: (abstract new () => {
|
|
188
|
-
toBytes(): ccc.Bytes;
|
|
189
|
-
clone(): DidCkbWitness;
|
|
190
|
-
eq(other: DidCkbWitnessLike): boolean;
|
|
191
|
-
hash(): ccc.Hex;
|
|
192
|
-
toHex(): ccc.Hex;
|
|
193
|
-
}) & {
|
|
194
|
-
byteLength?: number;
|
|
195
|
-
encode(_: DidCkbWitnessLike): ccc.Bytes;
|
|
196
|
-
decode(_: ccc.BytesLike): DidCkbWitness;
|
|
197
|
-
fromBytes(_bytes: ccc.BytesLike): DidCkbWitness;
|
|
198
|
-
from(_: DidCkbWitnessLike): DidCkbWitness;
|
|
199
|
-
Base<SubTypeLike, SubType = SubTypeLike>(): any;
|
|
200
|
-
BaseUnion<CodecType extends ccc.CodecLike<any, ccc.mol.UnionDecoded<any, any>>, SubTypeLike_1, SubType_1 = SubTypeLike_1>(): (abstract new (inner: ccc.DecodedType<CodecType>) => {
|
|
201
|
-
readonly inner: ccc.DecodedType<CodecType>;
|
|
202
|
-
match<Result>(handlers: ccc.mol.UnionMatchHandlers<CodecType, Result> & {
|
|
203
|
-
_?: undefined | null;
|
|
204
|
-
}): Result;
|
|
205
|
-
match<Result>(handlers: Partial<ccc.mol.UnionMatchHandlers<CodecType, Result>> & {
|
|
206
|
-
_: (inner: ccc.DecodedType<CodecType>) => Result;
|
|
207
|
-
}): Result;
|
|
208
|
-
toBytes(): ccc.Bytes;
|
|
209
|
-
clone(): SubType_1;
|
|
210
|
-
eq(other: SubTypeLike_1): boolean;
|
|
211
|
-
hash(): ccc.Hex;
|
|
212
|
-
toHex(): ccc.Hex;
|
|
213
|
-
}) & {
|
|
214
|
-
byteLength?: number;
|
|
215
|
-
encode(_: SubTypeLike_1): ccc.Bytes;
|
|
216
|
-
decode(_: ccc.BytesLike): SubType_1;
|
|
217
|
-
fromBytes(_bytes: ccc.BytesLike): SubType_1;
|
|
218
|
-
from(_: SubTypeLike_1): SubType_1;
|
|
219
|
-
Base<SubTypeLike, SubType = SubTypeLike>(): any;
|
|
220
|
-
BaseUnion<CodecType_1 extends ccc.CodecLike<any, ccc.mol.UnionDecoded<any, any>>, SubTypeLike_1_1, SubType_1_1 = SubTypeLike_1_1>(): any;
|
|
221
|
-
};
|
|
222
|
-
};
|
|
223
|
-
export declare class DidCkbWitness extends DidCkbWitness_base {
|
|
224
|
-
localIdAuthorization: PlcAuthorization;
|
|
225
|
-
constructor(localIdAuthorization: PlcAuthorization);
|
|
226
|
-
static from(data: DidCkbWitnessLike): DidCkbWitness;
|
|
227
|
-
}
|
|
228
|
-
//#endregion
|
|
229
|
-
//#region src/didCkb.d.ts
|
|
230
|
-
/**
|
|
231
|
-
* Create a DID CKB cell.
|
|
232
|
-
*
|
|
233
|
-
* @param props The arguments for creating the cell.
|
|
234
|
-
* @param props.signer The signer to sign the transaction.
|
|
235
|
-
* @param props.receiver The receiver script (optional).
|
|
236
|
-
* @param props.data The output data.
|
|
237
|
-
* @param props.tx The transaction skeleton (optional).
|
|
238
|
-
*/
|
|
239
|
-
export declare function createDidCkb(props: {
|
|
240
|
-
signer: ccc.Signer;
|
|
241
|
-
data: DidCkbDataLike;
|
|
242
|
-
receiver?: ccc.ScriptLike | null;
|
|
243
|
-
tx?: ccc.TransactionLike | null;
|
|
244
|
-
}): Promise<{
|
|
245
|
-
tx: ccc.Transaction;
|
|
246
|
-
id: ccc.Hex;
|
|
247
|
-
index: number;
|
|
248
|
-
}>;
|
|
249
|
-
/**
|
|
250
|
-
* Transfer a DID CKB cell.
|
|
251
|
-
*
|
|
252
|
-
* @param props The arguments for transferring the cell.
|
|
253
|
-
* @param props.client The client to communicate with CKB.
|
|
254
|
-
* @param props.id The Type ID to transfer.
|
|
255
|
-
* @param props.receiver The new receiver script.
|
|
256
|
-
* @param props.tx The transaction skeleton (optional).
|
|
257
|
-
* @param props.data The new output data or a transformer to update the data (optional).
|
|
258
|
-
*/
|
|
259
|
-
export declare function transferDidCkb(props: {
|
|
260
|
-
client: ccc.Client;
|
|
261
|
-
id: ccc.HexLike;
|
|
262
|
-
receiver: ccc.ScriptLike;
|
|
263
|
-
tx?: ccc.TransactionLike | null;
|
|
264
|
-
data?: DidCkbDataLike | ((cell: ccc.Cell, data?: DidCkbData) => DidCkbDataLike | Promise<DidCkbDataLike>) | null;
|
|
265
|
-
}): Promise<{
|
|
266
|
-
tx: ccc.Transaction;
|
|
267
|
-
inIndex: number;
|
|
268
|
-
outIndex: number;
|
|
269
|
-
}>;
|
|
270
|
-
/**
|
|
271
|
-
* Destroy a DID CKB cell.
|
|
272
|
-
*
|
|
273
|
-
* @param props The arguments for destroying the cell.
|
|
274
|
-
* @param props.client The client to communicate with CKB.
|
|
275
|
-
* @param props.id The Type ID to destroy.
|
|
276
|
-
* @param props.tx The transaction skeleton (optional).
|
|
277
|
-
*/
|
|
278
|
-
export declare function destroyDidCkb(props: {
|
|
279
|
-
client: ccc.Client;
|
|
280
|
-
id: ccc.HexLike;
|
|
281
|
-
tx?: ccc.TransactionLike | null;
|
|
282
|
-
}): Promise<{
|
|
283
|
-
tx: ccc.Transaction;
|
|
284
|
-
index: number;
|
|
285
|
-
}>;
|
|
286
|
-
//#endregion
|
|
287
|
-
//#region src/history.d.ts
|
|
288
|
-
export type HistoryAction = "CREATE" | "UPDATE" | "MIGRATE";
|
|
289
|
-
export type HistoryEntry = {
|
|
290
|
-
/**
|
|
291
|
-
* `CREATE` for a fresh mint, `MIGRATE` for a did:plc import (genesis cell
|
|
292
|
-
* with a `localId` set), `UPDATE` for every subsequent transfer.
|
|
293
|
-
*/
|
|
294
|
-
action: HistoryAction;
|
|
295
|
-
txHash: ccc.Hex;
|
|
296
|
-
outputIndex: ccc.Num;
|
|
297
|
-
blockNumber?: ccc.Num;
|
|
298
|
-
capacity: ccc.Num;
|
|
299
|
-
data: DidCkbData;
|
|
300
|
-
};
|
|
301
|
-
/**
|
|
302
|
-
* Walk the DID cell chain backwards to produce the ordered list of operations
|
|
303
|
-
* applied to a DID.
|
|
304
|
-
*
|
|
305
|
-
* Each `transferDidCkb` consumes the previous DID cell as an input and creates
|
|
306
|
-
* a new one with the same Type ID args; the genesis (`createDidCkb` /
|
|
307
|
-
* `createDidCkb` with localId) has no DID input. We start from the live cell,
|
|
308
|
-
* read its tx, look for the prior DID cell among the inputs, and repeat. The
|
|
309
|
-
* first entry returned is the newest (most recent transfer); the last is the
|
|
310
|
-
* genesis.
|
|
311
|
-
*
|
|
312
|
-
* Cost: roughly one `getTransaction` call per step plus one `input.getCell`
|
|
313
|
-
* lookup per non-DID input on each step. `input.getCell` goes through the
|
|
314
|
-
* client's cell cache, so repeated walks over the same chain are cheap.
|
|
315
|
-
*/
|
|
316
|
-
export declare function getDidCkbHistory(props: {
|
|
317
|
-
client: ccc.Client;
|
|
318
|
-
/**
|
|
319
|
-
* Either the 20-byte Type ID args hex returned by `createDidCkb`, or a
|
|
320
|
-
* `did:ckb:` URI. URIs are converted via `didToArgs`.
|
|
321
|
-
*/
|
|
322
|
-
id: ccc.HexLike | string;
|
|
323
|
-
/** Pre-resolved live cell; if omitted, we fetch it. */
|
|
324
|
-
liveCell?: ccc.Cell;
|
|
325
|
-
/** Safety bound to prevent runaway walks. Default 50. */
|
|
326
|
-
maxSteps?: number;
|
|
327
|
-
}): Promise<HistoryEntry[]>;
|
|
328
|
-
//#endregion
|
|
329
|
-
//#region src/identifier.d.ts
|
|
330
|
-
export declare function base32Encode(bytes: ccc.BytesLike): string;
|
|
331
|
-
export declare function base32Decode(input: string): ccc.Bytes;
|
|
332
|
-
/**
|
|
333
|
-
* Convert 20-byte Type ID args (the `id` returned from `createDidCkb`) to a
|
|
334
|
-
* `did:ckb:` identifier string per WIP-01 §2.2.
|
|
335
|
-
*/
|
|
336
|
-
export declare function argsToDid(args: ccc.HexLike): string;
|
|
337
|
-
/**
|
|
338
|
-
* Reverse of `argsToDid`. Validates the prefix, base32 length, and decoded
|
|
339
|
-
* byte count.
|
|
340
|
-
*/
|
|
341
|
-
export declare function didToArgs(did: string): ccc.Hex;
|
|
342
|
-
export declare function isDidCkb(value: string): boolean;
|
|
343
|
-
//#endregion
|
|
344
|
-
//#region src/migrate.d.ts
|
|
345
|
-
/**
|
|
346
|
-
* Build the migration witness payload that authorizes a did:plc -> did:ckb
|
|
347
|
-
* import. Pure: takes a tx hash + signing material, returns a typed
|
|
348
|
-
* `DidCkbWitness` that the caller wraps in a `WitnessArgs.outputType` field.
|
|
349
|
-
*
|
|
350
|
-
* Per WIP-02 §3.1.1 we send only the genesis operation in `history`. The
|
|
351
|
-
* contract recomputes the genesis CID over the CBOR-encoded op, verifies the
|
|
352
|
-
* self-signature inside it, then verifies `sig` against
|
|
353
|
-
* `history[0].rotationKeys[rotationKeyIndex]`.
|
|
354
|
-
*
|
|
355
|
-
* `selfSigIndex` defaults to 0 because PLC genesis ops are conventionally
|
|
356
|
-
* self-signed by the first rotation key; override if the genesis you're
|
|
357
|
-
* migrating used a different one.
|
|
358
|
-
*/
|
|
359
|
-
export declare function buildMigrationWitness(props: {
|
|
360
|
-
txHash: ccc.HexLike;
|
|
361
|
-
genesisOperation: PlcOperation;
|
|
362
|
-
rotationKeyIndex: number;
|
|
363
|
-
rotationPrivateKey: ccc.BytesLike;
|
|
364
|
-
curve?: Curve;
|
|
365
|
-
selfSigIndex?: number;
|
|
366
|
-
}): DidCkbWitness;
|
|
367
|
-
/**
|
|
368
|
-
* Build a create tx whose output declares an imported did:plc identifier in
|
|
369
|
-
* its `localId` field. Equivalent to calling `createDidCkb` with
|
|
370
|
-
* `data.value.localId = sourceDid`; provided as a named helper for symmetry
|
|
371
|
-
* with the other DID operations and so `did:plc:` migrations have an
|
|
372
|
-
* obvious entry point.
|
|
373
|
-
*
|
|
374
|
-
* The caller is responsible for: completing inputs + fee, building the
|
|
375
|
-
* migration witness with `buildMigrationWitness`, and setting it at the
|
|
376
|
-
* witness slot of input 0. See `packages/examples/src/migrateDid.ts` for the
|
|
377
|
-
* full flow.
|
|
378
|
-
*/
|
|
379
|
-
export declare function migrateDidCkb(props: {
|
|
380
|
-
signer: ccc.Signer;
|
|
381
|
-
sourceDid: string;
|
|
382
|
-
data?: DidCkbDataLike | null;
|
|
383
|
-
receiver?: ccc.ScriptLike | null;
|
|
384
|
-
tx?: ccc.TransactionLike | null;
|
|
385
|
-
}): Promise<{
|
|
386
|
-
tx: ccc.Transaction;
|
|
387
|
-
id: ccc.Hex;
|
|
388
|
-
index: number;
|
|
389
|
-
}>;
|
|
390
|
-
//#endregion
|
|
391
|
-
//#region src/resolver.d.ts
|
|
392
|
-
export type DidCkbRecord = {
|
|
393
|
-
/** The `did:ckb:` string identifying this cell. */
|
|
394
|
-
did: string;
|
|
395
|
-
/** 20-byte Type ID args (same value `createDidCkb` returned as `id`). */
|
|
396
|
-
id: ccc.Hex;
|
|
397
|
-
/** Decoded DidCkbData; `.value.document` is the CBOR-decoded document. */
|
|
398
|
-
data: DidCkbData;
|
|
399
|
-
/** The live DID Metadata Cell itself. */
|
|
400
|
-
cell: ccc.Cell;
|
|
401
|
-
};
|
|
402
|
-
/**
|
|
403
|
-
* Find the live DID Metadata Cell for a given Type ID and decode its data.
|
|
404
|
-
*
|
|
405
|
-
* Returns `undefined` when no live cell exists (the DID was never created or
|
|
406
|
-
* has been destroyed).
|
|
407
|
-
*/
|
|
408
|
-
export declare function findDidCkbCell(props: {
|
|
409
|
-
client: ccc.Client;
|
|
410
|
-
id: ccc.HexLike;
|
|
411
|
-
}): Promise<DidCkbRecord | undefined>;
|
|
412
|
-
/**
|
|
413
|
-
* Resolve a `did:ckb:` string to its live cell + decoded document.
|
|
414
|
-
*
|
|
415
|
-
* Throws if `did` is not a syntactically valid did:ckb identifier. Returns
|
|
416
|
-
* `undefined` if the DID was created and then destroyed, or never existed.
|
|
417
|
-
*/
|
|
418
|
-
export declare function resolveDidCkb(props: {
|
|
419
|
-
client: ccc.Client;
|
|
420
|
-
did: string;
|
|
421
|
-
}): Promise<DidCkbRecord | undefined>;
|
|
422
|
-
/**
|
|
423
|
-
* List every live DID Metadata Cell owned by the given lock. Useful for
|
|
424
|
-
* dashboards that want to enumerate the DIDs an address controls.
|
|
425
|
-
*
|
|
426
|
-
* Cells whose data fails to decode (e.g. a future on-chain schema version) are
|
|
427
|
-
* skipped, not thrown, so a single bad cell can't break the whole listing.
|
|
428
|
-
*/
|
|
429
|
-
export declare function listDidCkbsByLock(props: {
|
|
430
|
-
client: ccc.Client;
|
|
431
|
-
lock: ccc.ScriptLike;
|
|
432
|
-
limit?: number;
|
|
433
|
-
order?: "asc" | "desc";
|
|
434
|
-
}): Promise<DidCkbRecord[]>;
|
|
435
|
-
declare namespace barrel_d_exports {
|
|
436
|
-
export { DidCkbData, DidCkbDataLike, DidCkbDataV1, DidCkbDataV1Like, DidCkbRecord, DidCkbWitness, DidCkbWitnessLike, HistoryAction, HistoryEntry, PlcAuthorization, PlcAuthorizationLike, argsToDid, base32Decode, base32Encode, buildMigrationWitness, createDidCkb, destroyDidCkb, didToArgs, findDidCkbCell, getDidCkbHistory, isDidCkb, listDidCkbsByLock, migrateDidCkb, index_d_exports as plc, resolveDidCkb, transferDidCkb };
|
|
437
|
-
}
|
|
438
|
-
//#endregion
|
|
439
|
-
export { index_d_exports as plc, barrel_d_exports as t };
|
|
440
|
-
//# sourceMappingURL=barrel.d.ts.map
|
|
1
|
+
import { C as DidCkbWitness, E as PlcAuthorizationLike, S as DidCkbDataV1Like, T as PlcAuthorization, _ as destroyDidCkb, a as resolveDidCkb, b as DidCkbDataLike, c as argsToDid, d as didToArgs, f as isDidCkb, g as createDidCkb, h as getDidCkbHistory, i as listDidCkbsByLock, l as base32Decode, m as HistoryEntry, n as DidCkbRecord, o as buildMigrationWitness, p as HistoryAction, r as findDidCkbCell, s as migrateDidCkb, u as base32Encode, v as transferDidCkb, w as DidCkbWitnessLike, x as DidCkbDataV1, y as DidCkbData } from "./barrel-9fYvfkI1.js";
|
|
2
|
+
import { s as index_d_exports } from "./index-C0QY5P5_.js";
|
|
3
|
+
export { DidCkbData, DidCkbDataLike, DidCkbDataV1, DidCkbDataV1Like, DidCkbRecord, DidCkbWitness, DidCkbWitnessLike, HistoryAction, HistoryEntry, PlcAuthorization, PlcAuthorizationLike, argsToDid, base32Decode, base32Encode, buildMigrationWitness, createDidCkb, destroyDidCkb, didToArgs, findDidCkbCell, getDidCkbHistory, isDidCkb, listDidCkbsByLock, migrateDidCkb, index_d_exports as plc, resolveDidCkb, transferDidCkb };
|
package/dist.commonjs/barrel.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./plc-DMi9GhTp.js"),t=require("./barrel-BWApUcdp.js");Object.defineProperty(exports,"DidCkbData",{enumerable:!0,get:function(){return t.g}}),Object.defineProperty(exports,"DidCkbDataV1",{enumerable:!0,get:function(){return t._}}),Object.defineProperty(exports,"DidCkbWitness",{enumerable:!0,get:function(){return t.v}}),Object.defineProperty(exports,"PlcAuthorization",{enumerable:!0,get:function(){return t.y}}),exports.argsToDid=t.c,exports.base32Decode=t.l,exports.base32Encode=t.u,exports.buildMigrationWitness=t.n,exports.createDidCkb=t.p,exports.destroyDidCkb=t.m,exports.didToArgs=t.d,exports.findDidCkbCell=t.a,exports.getDidCkbHistory=t.i,exports.isDidCkb=t.f,exports.listDidCkbsByLock=t.o,exports.migrateDidCkb=t.r,Object.defineProperty(exports,"plc",{enumerable:!0,get:function(){return e.a}}),exports.resolveDidCkb=t.s,exports.transferDidCkb=t.h;
|
|
@@ -60,6 +60,5 @@ declare function signRotationHash(privateKey: ccc.BytesLike, txHash: ccc.BytesLi
|
|
|
60
60
|
* rotation slot" without waiting for an on-chain rejection.
|
|
61
61
|
*/
|
|
62
62
|
declare function verifyPrivateKeyMatch(privateKey: ccc.BytesLike, expectedPubkey: ccc.BytesLike, curve: Curve): boolean;
|
|
63
|
-
//#endregion
|
|
64
63
|
export { getGenesisOperation as a, parseDidKey as c, fetchPlcLog as i, signRotationHash as l, PlcOperation as n, getRotationKeys as o, PlcRotationKey as r, index_d_exports as s, Curve as t, verifyPrivateKeyMatch as u };
|
|
65
|
-
//# sourceMappingURL=index-
|
|
64
|
+
//# sourceMappingURL=index-C0QY5P5_.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-C0QY5P5_.d.ts","names":[],"sources":["../src/plc/index.ts"],"mappings":";;;;KAgBY;KAEA;EACV;EACA,OAAO;EACP,kBAAkB,IAAI;;KAGZ;EACV;EACA;EACA,sBAAsB;EACtB;EACA,WAAW;IAAiB;IAAc;;EAC1C;EACA;EAEA;EACA;EACA;EACA;GACC;;;;;;iBAOmB,YACpB,aACA,qBACC,QAAQ;iBAeK,oBAAoB,KAAK,iBAAiB;;;;;;;;iBAc1C,gBAAgB,IAAI,eAAe;iBAsBnC,YAAY;EAC1B,OAAO;EACP,kBAAkB,IAAI;;;;;;;;;;;;iBAoCR,iBACd,YAAY,IAAI,WAChB,QAAQ,IAAI,WACZ,OAAO,QACN,IAAI;;;;;;iBA4BS,sBACd,YAAY,IAAI,WAChB,gBAAgB,IAAI,WACpB,OAAO"}
|
package/dist.commonjs/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { s as
|
|
2
|
-
import {
|
|
1
|
+
import { C as DidCkbWitness, E as PlcAuthorizationLike, S as DidCkbDataV1Like, T as PlcAuthorization, _ as destroyDidCkb, a as resolveDidCkb, b as DidCkbDataLike, c as argsToDid, d as didToArgs, f as isDidCkb, g as createDidCkb, h as getDidCkbHistory, i as listDidCkbsByLock, l as base32Decode, m as HistoryEntry, n as DidCkbRecord, o as buildMigrationWitness, p as HistoryAction, r as findDidCkbCell, s as migrateDidCkb, t as barrel_d_exports, u as base32Encode, v as transferDidCkb, w as DidCkbWitnessLike, x as DidCkbDataV1, y as DidCkbData } from "./barrel-9fYvfkI1.js";
|
|
2
|
+
import { s as index_d_exports } from "./index-C0QY5P5_.js";
|
|
3
3
|
export { DidCkbData, DidCkbDataLike, DidCkbDataV1, DidCkbDataV1Like, DidCkbRecord, DidCkbWitness, DidCkbWitnessLike, HistoryAction, HistoryEntry, PlcAuthorization, PlcAuthorizationLike, argsToDid, base32Decode, base32Encode, buildMigrationWitness, createDidCkb, destroyDidCkb, barrel_d_exports as didCkb, didToArgs, findDidCkbCell, getDidCkbHistory, isDidCkb, listDidCkbsByLock, migrateDidCkb, index_d_exports as plc, resolveDidCkb, transferDidCkb };
|
package/dist.commonjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./plc-DMi9GhTp.js"),t=require("./barrel-BWApUcdp.js");Object.defineProperty(exports,"DidCkbData",{enumerable:!0,get:function(){return t.g}}),Object.defineProperty(exports,"DidCkbDataV1",{enumerable:!0,get:function(){return t._}}),Object.defineProperty(exports,"DidCkbWitness",{enumerable:!0,get:function(){return t.v}}),Object.defineProperty(exports,"PlcAuthorization",{enumerable:!0,get:function(){return t.y}}),exports.argsToDid=t.c,exports.base32Decode=t.l,exports.base32Encode=t.u,exports.buildMigrationWitness=t.n,exports.createDidCkb=t.p,exports.destroyDidCkb=t.m,Object.defineProperty(exports,"didCkb",{enumerable:!0,get:function(){return t.t}}),exports.didToArgs=t.d,exports.findDidCkbCell=t.a,exports.getDidCkbHistory=t.i,exports.isDidCkb=t.f,exports.listDidCkbsByLock=t.o,exports.migrateDidCkb=t.r,Object.defineProperty(exports,"plc",{enumerable:!0,get:function(){return e.a}}),exports.resolveDidCkb=t.s,exports.transferDidCkb=t.h;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=Object.defineProperty,t=(t,n)=>{let r=Object.setPrototypeOf({},null);for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n&1||e(r,Symbol.toStringTag,{value:`Module`}),n&2?r:Object.preventExtensions(r)};let n=require("@ckb-ccc/core"),r=require("@noble/curves/nist.js"),i=require("@noble/curves/secp256k1.js");var a=/* @__PURE__ */ t({fetchPlcLog:()=>o,getGenesisOperation:()=>s,getRotationKeys:()=>c,parseDidKey:()=>l,signRotationHash:()=>u,verifyPrivateKeyMatch:()=>d});async function o(e,t=`https://plc.directory`){if(!e.startsWith(`did:plc:`))throw Error(`Expected did:plc identifier, got "${e}"`);let n=await fetch(`${t}/${e}/log`);if(!n.ok)throw Error(`PLC log fetch failed (${n.status} ${n.statusText})`);let r=await n.json();if(!Array.isArray(r)||r.length===0)throw Error(`PLC log empty or malformed`);return r}function s(e){if(e.length===0)throw Error(`Empty PLC log`);return e[0]}function c(e){let t=[];return e.rotationKeys?.length?t.push(...e.rotationKeys):(e.signingKey||e.recoveryKey)&&(e.signingKey&&t.push(e.signingKey),e.recoveryKey&&t.push(e.recoveryKey)),t.map(e=>{let t=l(e);return{didKey:e,curve:t.curve,compressedPubkey:t.compressedPubkey}})}function l(e){if(!e.startsWith(`did:key:z`))throw Error(`Expected did:key:z..., got "${e}"`);let t=p(e.slice(9));if(t.length!==35)throw Error(`did:key payload must be 35 bytes (2-byte multicodec tag + 33-byte compressed pubkey), got ${t.length}`);let n=t[0],r=t[1],i;if(n===231&&r===1)i=`secp256k1`;else if(n===128&&r===36)i=`p256`;else throw Error(`Unrecognised did:key multicodec tag: 0x${n.toString(16).padStart(2,`0`)} 0x${r.toString(16).padStart(2,`0`)}`);return{curve:i,compressedPubkey:t.subarray(2)}}function u(e,t,a){let o=n.ccc.bytesFrom(t);if(o.length!==32)throw Error(`Expected 32-byte tx hash, got ${o.length}`);let s=n.ccc.bytesFrom(e);if(s.length!==32)throw Error(`Expected 32-byte private key, got ${s.length}`);return a===`secp256k1`?i.secp256k1.sign(o,s,{prehash:!0,lowS:!0,format:`compact`}):r.p256.sign(o,s,{prehash:!0,lowS:!0,format:`compact`})}function d(e,t,a){let o=n.ccc.bytesFrom(e);if(o.length!==32)return!1;let s=n.ccc.bytesFrom(t),c=a===`secp256k1`?i.secp256k1.getPublicKey(o,!0):r.p256.getPublicKey(o,!0);if(c.length!==s.length)return!1;for(let e=0;e<c.length;e++)if(c[e]!==s[e])return!1;return!0}const f=(()=>{let e={};for(let t=0;t<58;t++)e[`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`[t]]=t;return e})();function p(e){if(e.length===0)return/* @__PURE__ */ new Uint8Array;let t=0;for(;t<e.length&&e[t]===`1`;)t++;let n=0n;for(let r=t;r<e.length;r++){let t=e[r],i=f[t];if(i===void 0)throw Error(`Invalid base58 character "${t}"`);n=n*58n+BigInt(i)}let r=[];for(;n>0n;)r.unshift(Number(n&255n)),n>>=8n;return Uint8Array.from([...Array(t).fill(0),...r])}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return o}});
|
|
2
|
+
//# sourceMappingURL=plc-DMi9GhTp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plc.js","names":["ccc","secp256k1","p256"],"sources":["../src/plc/index.ts"],"sourcesContent":["import { ccc } from \"@ckb-ccc/core\";\nimport { p256 } from \"@noble/curves/nist.js\";\nimport { secp256k1 } from \"@noble/curves/secp256k1.js\";\n\n/**\n * Minimal did:plc helpers, scoped to what a did:ckb migration needs:\n * fetch the op log from the public PLC directory, parse rotation keys, and\n * sign a 32-byte CKB transaction hash with a rotation private key.\n *\n * The on-chain contract is happy with a history of length 1 (WIP-02 §3.1.1\n * RECOMMENDs the genesis-only form), so we don't walk the full op chain\n * client-side.\n */\n\nconst PLC_DIRECTORY = \"https://plc.directory\";\n\nexport type Curve = \"secp256k1\" | \"p256\";\n\nexport type PlcRotationKey = {\n didKey: string;\n curve: Curve;\n compressedPubkey: ccc.Bytes;\n};\n\nexport type PlcOperation = {\n type: string;\n rotationKeys?: string[];\n verificationMethods?: Record<string, string>;\n alsoKnownAs?: string[];\n services?: Record<string, { type: string; endpoint: string }>;\n prev: string | null;\n sig: string;\n // Legacy `create` op fields:\n signingKey?: string;\n recoveryKey?: string;\n handle?: string;\n service?: string;\n [key: string]: unknown;\n};\n\n/**\n * Fetch the operation log for a did:plc identifier from the public directory.\n * Pass a custom directory URL when targeting a staging environment.\n */\nexport async function fetchPlcLog(\n did: string,\n directory: string = PLC_DIRECTORY,\n): Promise<PlcOperation[]> {\n if (!did.startsWith(\"did:plc:\")) {\n throw new Error(`Expected did:plc identifier, got \"${did}\"`);\n }\n const res = await fetch(`${directory}/${did}/log`);\n if (!res.ok) {\n throw new Error(`PLC log fetch failed (${res.status} ${res.statusText})`);\n }\n const data: unknown = await res.json();\n if (!Array.isArray(data) || data.length === 0) {\n throw new Error(\"PLC log empty or malformed\");\n }\n return data as PlcOperation[];\n}\n\nexport function getGenesisOperation(log: PlcOperation[]): PlcOperation {\n if (log.length === 0) {\n throw new Error(\"Empty PLC log\");\n }\n return log[0];\n}\n\n/**\n * Surface the rotation keys declared in a genesis op as a uniform list. PLC\n * genesis comes in two shapes: the modern `plc_operation` (with\n * `rotationKeys`) and the deprecated `create` (with `signingKey` +\n * `recoveryKey`). The on-chain contract treats the legacy form as\n * `[signingKey, recoveryKey]`, so we expose the same order.\n */\nexport function getRotationKeys(op: PlcOperation): PlcRotationKey[] {\n const keys: string[] = [];\n if (op.rotationKeys?.length) {\n keys.push(...op.rotationKeys);\n } else if (op.signingKey || op.recoveryKey) {\n if (op.signingKey) {\n keys.push(op.signingKey);\n }\n if (op.recoveryKey) {\n keys.push(op.recoveryKey);\n }\n }\n return keys.map((didKey) => {\n const parsed = parseDidKey(didKey);\n return {\n didKey,\n curve: parsed.curve,\n compressedPubkey: parsed.compressedPubkey,\n };\n });\n}\n\nexport function parseDidKey(didKey: string): {\n curve: Curve;\n compressedPubkey: ccc.Bytes;\n} {\n if (!didKey.startsWith(\"did:key:z\")) {\n throw new Error(`Expected did:key:z..., got \"${didKey}\"`);\n }\n const raw = base58btcDecode(didKey.slice(\"did:key:z\".length));\n if (raw.length !== 35) {\n throw new Error(\n `did:key payload must be 35 bytes (2-byte multicodec tag + 33-byte compressed pubkey), got ${raw.length}`,\n );\n }\n const tag1 = raw[0];\n const tag2 = raw[1];\n let curve: Curve;\n if (tag1 === 0xe7 && tag2 === 0x01) {\n curve = \"secp256k1\";\n } else if (tag1 === 0x80 && tag2 === 0x24) {\n curve = \"p256\";\n } else {\n throw new Error(\n `Unrecognised did:key multicodec tag: 0x${tag1.toString(16).padStart(2, \"0\")} 0x${tag2.toString(16).padStart(2, \"0\")}`,\n );\n }\n return { curve, compressedPubkey: raw.subarray(2) };\n}\n\n/**\n * Sign a 32-byte CKB tx hash with a PLC rotation private key.\n *\n * The on-chain validator runs k256/p256's `Verifier::verify` which internally\n * SHA-256 hashes the message before checking the ECDSA signature. Noble's\n * default is the opposite (treat input as already-hashed), so we pass\n * `prehash: true` to make noble apply SHA-256 internally and match the\n * contract. Output is canonical low-s 64-byte compact form, identical to\n * what @atproto/crypto's Keypair.sign produces.\n */\nexport function signRotationHash(\n privateKey: ccc.BytesLike,\n txHash: ccc.BytesLike,\n curve: Curve,\n): ccc.Bytes {\n const hash = ccc.bytesFrom(txHash);\n if (hash.length !== 32) {\n throw new Error(`Expected 32-byte tx hash, got ${hash.length}`);\n }\n const priv = ccc.bytesFrom(privateKey);\n if (priv.length !== 32) {\n throw new Error(`Expected 32-byte private key, got ${priv.length}`);\n }\n if (curve === \"secp256k1\") {\n return secp256k1.sign(hash, priv, {\n prehash: true,\n lowS: true,\n format: \"compact\",\n });\n }\n return p256.sign(hash, priv, {\n prehash: true,\n lowS: true,\n format: \"compact\",\n });\n}\n\n/**\n * Quick sanity check: derive the public key from `privateKey` and compare\n * against `expectedPubkey`. Lets a UI tell the user \"wrong key for this\n * rotation slot\" without waiting for an on-chain rejection.\n */\nexport function verifyPrivateKeyMatch(\n privateKey: ccc.BytesLike,\n expectedPubkey: ccc.BytesLike,\n curve: Curve,\n): boolean {\n const priv = ccc.bytesFrom(privateKey);\n if (priv.length !== 32) {\n return false;\n }\n const expected = ccc.bytesFrom(expectedPubkey);\n const pub =\n curve === \"secp256k1\"\n ? secp256k1.getPublicKey(priv, true)\n : p256.getPublicKey(priv, true);\n if (pub.length !== expected.length) {\n return false;\n }\n for (let i = 0; i < pub.length; i++) {\n if (pub[i] !== expected[i]) {\n return false;\n }\n }\n return true;\n}\n\n// Inline base58btc decode (Bitcoin alphabet) so we don't pull in multiformats\n// as a direct dependency. Audited by the multicodec tag round-trip tests.\nconst BASE58_ALPHABET =\n \"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\";\nconst BASE58_REVERSE: Record<string, number> = (() => {\n const m: Record<string, number> = {};\n for (let i = 0; i < BASE58_ALPHABET.length; i++) {\n m[BASE58_ALPHABET[i]] = i;\n }\n return m;\n})();\n\nfunction base58btcDecode(input: string): ccc.Bytes {\n if (input.length === 0) {\n return new Uint8Array(0);\n }\n let leadingOnes = 0;\n while (leadingOnes < input.length && input[leadingOnes] === \"1\") {\n leadingOnes++;\n }\n let value = 0n;\n for (let i = leadingOnes; i < input.length; i++) {\n const c = input[i];\n const v = BASE58_REVERSE[c];\n if (v === undefined) {\n throw new Error(`Invalid base58 character \"${c}\"`);\n }\n value = value * 58n + BigInt(v);\n }\n const tail: number[] = [];\n while (value > 0n) {\n tail.unshift(Number(value & 0xffn));\n value >>= 8n;\n }\n return Uint8Array.from([...Array<number>(leadingOnes).fill(0), ...tail]);\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"plc-DMi9GhTp.js","names":["ccc","secp256k1","p256","__defProp","__exportAll","target","name","all","flags","_ckb_ccc_core","_noble_curves_nist_js","_noble_curves_secp256k1_js","plc_exports","fetchPlcLog","getGenesisOperation","getRotationKeys","parseDidKey","signRotationHash","verifyPrivateKeyMatch","did","res","directory","data","log","keys","op","parsed","didKey","raw","base58btcDecode","tag1","tag2","curve","hash","txHash","priv","privateKey","expected","expectedPubkey","pub","i","BASE58_REVERSE","m","input","leadingOnes","value","c","v","tail"],"sources":["../src/plc/index.ts"],"sourcesContent":["import { ccc } from \"@ckb-ccc/core\";\nimport { p256 } from \"@noble/curves/nist.js\";\nimport { secp256k1 } from \"@noble/curves/secp256k1.js\";\n\n/**\n * Minimal did:plc helpers, scoped to what a did:ckb migration needs:\n * fetch the op log from the public PLC directory, parse rotation keys, and\n * sign a 32-byte CKB transaction hash with a rotation private key.\n *\n * The on-chain contract is happy with a history of length 1 (WIP-02 §3.1.1\n * RECOMMENDs the genesis-only form), so we don't walk the full op chain\n * client-side.\n */\n\nconst PLC_DIRECTORY = \"https://plc.directory\";\n\nexport type Curve = \"secp256k1\" | \"p256\";\n\nexport type PlcRotationKey = {\n didKey: string;\n curve: Curve;\n compressedPubkey: ccc.Bytes;\n};\n\nexport type PlcOperation = {\n type: string;\n rotationKeys?: string[];\n verificationMethods?: Record<string, string>;\n alsoKnownAs?: string[];\n services?: Record<string, { type: string; endpoint: string }>;\n prev: string | null;\n sig: string;\n // Legacy `create` op fields:\n signingKey?: string;\n recoveryKey?: string;\n handle?: string;\n service?: string;\n [key: string]: unknown;\n};\n\n/**\n * Fetch the operation log for a did:plc identifier from the public directory.\n * Pass a custom directory URL when targeting a staging environment.\n */\nexport async function fetchPlcLog(\n did: string,\n directory: string = PLC_DIRECTORY,\n): Promise<PlcOperation[]> {\n if (!did.startsWith(\"did:plc:\")) {\n throw new Error(`Expected did:plc identifier, got \"${did}\"`);\n }\n const res = await fetch(`${directory}/${did}/log`);\n if (!res.ok) {\n throw new Error(`PLC log fetch failed (${res.status} ${res.statusText})`);\n }\n const data: unknown = await res.json();\n if (!Array.isArray(data) || data.length === 0) {\n throw new Error(\"PLC log empty or malformed\");\n }\n return data as PlcOperation[];\n}\n\nexport function getGenesisOperation(log: PlcOperation[]): PlcOperation {\n if (log.length === 0) {\n throw new Error(\"Empty PLC log\");\n }\n return log[0];\n}\n\n/**\n * Surface the rotation keys declared in a genesis op as a uniform list. PLC\n * genesis comes in two shapes: the modern `plc_operation` (with\n * `rotationKeys`) and the deprecated `create` (with `signingKey` +\n * `recoveryKey`). The on-chain contract treats the legacy form as\n * `[signingKey, recoveryKey]`, so we expose the same order.\n */\nexport function getRotationKeys(op: PlcOperation): PlcRotationKey[] {\n const keys: string[] = [];\n if (op.rotationKeys?.length) {\n keys.push(...op.rotationKeys);\n } else if (op.signingKey || op.recoveryKey) {\n if (op.signingKey) {\n keys.push(op.signingKey);\n }\n if (op.recoveryKey) {\n keys.push(op.recoveryKey);\n }\n }\n return keys.map((didKey) => {\n const parsed = parseDidKey(didKey);\n return {\n didKey,\n curve: parsed.curve,\n compressedPubkey: parsed.compressedPubkey,\n };\n });\n}\n\nexport function parseDidKey(didKey: string): {\n curve: Curve;\n compressedPubkey: ccc.Bytes;\n} {\n if (!didKey.startsWith(\"did:key:z\")) {\n throw new Error(`Expected did:key:z..., got \"${didKey}\"`);\n }\n const raw = base58btcDecode(didKey.slice(\"did:key:z\".length));\n if (raw.length !== 35) {\n throw new Error(\n `did:key payload must be 35 bytes (2-byte multicodec tag + 33-byte compressed pubkey), got ${raw.length}`,\n );\n }\n const tag1 = raw[0];\n const tag2 = raw[1];\n let curve: Curve;\n if (tag1 === 0xe7 && tag2 === 0x01) {\n curve = \"secp256k1\";\n } else if (tag1 === 0x80 && tag2 === 0x24) {\n curve = \"p256\";\n } else {\n throw new Error(\n `Unrecognised did:key multicodec tag: 0x${tag1.toString(16).padStart(2, \"0\")} 0x${tag2.toString(16).padStart(2, \"0\")}`,\n );\n }\n return { curve, compressedPubkey: raw.subarray(2) };\n}\n\n/**\n * Sign a 32-byte CKB tx hash with a PLC rotation private key.\n *\n * The on-chain validator runs k256/p256's `Verifier::verify` which internally\n * SHA-256 hashes the message before checking the ECDSA signature. Noble's\n * default is the opposite (treat input as already-hashed), so we pass\n * `prehash: true` to make noble apply SHA-256 internally and match the\n * contract. Output is canonical low-s 64-byte compact form, identical to\n * what @atproto/crypto's Keypair.sign produces.\n */\nexport function signRotationHash(\n privateKey: ccc.BytesLike,\n txHash: ccc.BytesLike,\n curve: Curve,\n): ccc.Bytes {\n const hash = ccc.bytesFrom(txHash);\n if (hash.length !== 32) {\n throw new Error(`Expected 32-byte tx hash, got ${hash.length}`);\n }\n const priv = ccc.bytesFrom(privateKey);\n if (priv.length !== 32) {\n throw new Error(`Expected 32-byte private key, got ${priv.length}`);\n }\n if (curve === \"secp256k1\") {\n return secp256k1.sign(hash, priv, {\n prehash: true,\n lowS: true,\n format: \"compact\",\n });\n }\n return p256.sign(hash, priv, {\n prehash: true,\n lowS: true,\n format: \"compact\",\n });\n}\n\n/**\n * Quick sanity check: derive the public key from `privateKey` and compare\n * against `expectedPubkey`. Lets a UI tell the user \"wrong key for this\n * rotation slot\" without waiting for an on-chain rejection.\n */\nexport function verifyPrivateKeyMatch(\n privateKey: ccc.BytesLike,\n expectedPubkey: ccc.BytesLike,\n curve: Curve,\n): boolean {\n const priv = ccc.bytesFrom(privateKey);\n if (priv.length !== 32) {\n return false;\n }\n const expected = ccc.bytesFrom(expectedPubkey);\n const pub =\n curve === \"secp256k1\"\n ? secp256k1.getPublicKey(priv, true)\n : p256.getPublicKey(priv, true);\n if (pub.length !== expected.length) {\n return false;\n }\n for (let i = 0; i < pub.length; i++) {\n if (pub[i] !== expected[i]) {\n return false;\n }\n }\n return true;\n}\n\n// Inline base58btc decode (Bitcoin alphabet) so we don't pull in multiformats\n// as a direct dependency. Audited by the multicodec tag round-trip tests.\nconst BASE58_ALPHABET =\n \"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\";\nconst BASE58_REVERSE: Record<string, number> = (() => {\n const m: Record<string, number> = {};\n for (let i = 0; i < BASE58_ALPHABET.length; i++) {\n m[BASE58_ALPHABET[i]] = i;\n }\n return m;\n})();\n\nfunction base58btcDecode(input: string): ccc.Bytes {\n if (input.length === 0) {\n return new Uint8Array(0);\n }\n let leadingOnes = 0;\n while (leadingOnes < input.length && input[leadingOnes] === \"1\") {\n leadingOnes++;\n }\n let value = 0n;\n for (let i = leadingOnes; i < input.length; i++) {\n const c = input[i];\n const v = BASE58_REVERSE[c];\n if (v === undefined) {\n throw new Error(`Invalid base58 character \"${c}\"`);\n }\n value = value * 58n + BigInt(v);\n }\n const tail: number[] = [];\n while (value > 0n) {\n tail.unshift(Number(value & 0xffn));\n value >>= 8n;\n }\n return Uint8Array.from([...Array<number>(leadingOnes).fill(0), ...tail]);\n}\n"],"mappings":"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"}
|
package/dist.commonjs/plc.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as getGenesisOperation, c as parseDidKey, i as fetchPlcLog, l as signRotationHash, n as PlcOperation, o as getRotationKeys, r as PlcRotationKey, t as Curve, u as verifyPrivateKeyMatch } from "./index-
|
|
1
|
+
import { a as getGenesisOperation, c as parseDidKey, i as fetchPlcLog, l as signRotationHash, n as PlcOperation, o as getRotationKeys, r as PlcRotationKey, t as Curve, u as verifyPrivateKeyMatch } from "./index-C0QY5P5_.js";
|
|
2
2
|
export { Curve, PlcOperation, PlcRotationKey, fetchPlcLog, getGenesisOperation, getRotationKeys, parseDidKey, signRotationHash, verifyPrivateKeyMatch };
|
package/dist.commonjs/plc.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./
|
|
2
|
-
//# sourceMappingURL=plc.js.map
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./plc-DMi9GhTp.js");exports.fetchPlcLog=e.t,exports.getGenesisOperation=e.n,exports.getRotationKeys=e.r,exports.parseDidKey=e.i,exports.signRotationHash=e.o,exports.verifyPrivateKeyMatch=e.s;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/did-ckb",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"description": "CCC - CKBer's Codebase. CCC's support for DID on CKB",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@ipld/dag-cbor": "^10.0.1",
|
|
49
49
|
"@noble/curves": "^2.2.0",
|
|
50
|
-
"@ckb-ccc/core": "1.
|
|
51
|
-
"@ckb-ccc/type-id": "0.1.
|
|
50
|
+
"@ckb-ccc/core": "1.23.1",
|
|
51
|
+
"@ckb-ccc/type-id": "0.1.16"
|
|
52
52
|
},
|
|
53
53
|
"types": "./dist.commonjs/index.d.ts",
|
|
54
54
|
"inlinedDependencies": {
|
package/src/history.ts
CHANGED
|
@@ -34,6 +34,9 @@ const DEFAULT_MAX_STEPS = 50;
|
|
|
34
34
|
* Cost: roughly one `getTransaction` call per step plus one `input.getCell`
|
|
35
35
|
* lookup per non-DID input on each step. `input.getCell` goes through the
|
|
36
36
|
* client's cell cache, so repeated walks over the same chain are cheap.
|
|
37
|
+
*
|
|
38
|
+
* @throws If an input cell lookup fails or the input cell is unavailable.
|
|
39
|
+
* An unresolved input cannot establish that a transaction is the genesis.
|
|
37
40
|
*/
|
|
38
41
|
export async function getDidCkbHistory(props: {
|
|
39
42
|
client: ccc.Client;
|
|
@@ -109,14 +112,7 @@ async function findPriorDidCell(
|
|
|
109
112
|
): Promise<ccc.Cell | undefined> {
|
|
110
113
|
const { inputs } = ccc.Transaction.from(tx);
|
|
111
114
|
for (const input of inputs) {
|
|
112
|
-
|
|
113
|
-
try {
|
|
114
|
-
cell = await input.getCell(client);
|
|
115
|
-
} catch {
|
|
116
|
-
// Skip inputs whose previous output we can't fetch; they can't be the
|
|
117
|
-
// prior DID cell anyway, so the walk should keep looking at siblings.
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
115
|
+
const cell = await input.getCell(client);
|
|
120
116
|
const type = cell.cellOutput.type;
|
|
121
117
|
if (!type) {
|
|
122
118
|
continue;
|
package/dist/barrel-DEJnxd4o.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime-DK3Fl9T5.mjs";import{getRotationKeys as t,signRotationHash as n,t as r}from"./plc.mjs";import{ccc as i}from"@ckb-ccc/core";import{decode as a,encode as o}from"@ipld/dag-cbor";import{typeIdA as s}from"@ckb-ccc/type-id/advanced";function c(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var l,u,d,f;let p=l=class extends i.Entity.Base(){constructor(e,t){super(),this.document=e,this.localId=t}static from(e){return e instanceof l?e:new l(e.document,e.localId??void 0)}};p=l=c([i.codec(i.mol.table({document:i.mol.Bytes,localId:i.mol.StringOpt}).map({inMap:e=>({...e,document:i.hexFrom(o(e.document))}),outMap:e=>({...e,document:a(i.bytesFrom(e.document))})}))],p);const m=i.mol.union({v1:p});let h=u=class extends i.Entity.BaseUnion(){constructor(e,t){super({type:e,value:t}),this.type=e,this.value=t}static from(e){return e instanceof u?e:`inner`in e?new u(e.inner.type??`v1`,p.from(e.inner.value)):new u(e.type??`v1`,p.from(e.value))}static fromV1(e){return new u(`v1`,p.from(e))}};h=u=c([i.codec(m)],h);let g=d=class extends i.Entity.Base(){constructor(e,t,n){super(),this.history=e,this.sig=t,this.rotationKeyIndices=n}static from(e){return e instanceof d?e:new d(e.history,i.hexFrom(e.sig),e.rotationKeyIndices.map(i.numFrom))}};g=d=c([i.codec(i.mol.table({history:i.mol.BytesVec,sig:i.mol.Bytes,rotationKeyIndices:i.mol.Uint8Vec}).map({inMap:e=>({...e,history:e.history.map(e=>i.hexFrom(o(e)))}),outMap:e=>({...e,history:e.history.map(e=>a(i.bytesFrom(e)))})}))],g);let _=f=class extends i.Entity.Base(){constructor(e){super(),this.localIdAuthorization=e}static from(e){return e instanceof f?e:new f(g.from(e.localIdAuthorization))}};_=f=c([i.codec(i.mol.table({localIdAuthorization:g}))],_);const v=s.buildTypeIdOperations({async getScriptInfo(e){return e.getKnownScript(i.KnownScript.DidCkb)},codec:h,async calculateTypeId(e,t){return i.bytesFrom(i.hashTypeId(t.inputs[0],t.outputs.length)).slice(0,20)}});function y(e){return v.create(e)}async function b(e){return v.transfer(e)}async function x(e){return v.destroy(e)}const S=`did:ckb:`,C=`abcdefghijklmnopqrstuvwxyz234567`,w=(()=>{let e={};for(let t=0;t<32;t++)e[C[t]]=t;return e})();function T(e){let t=i.bytesFrom(e),n=0,r=0,a=``;for(let e=0;e<t.length;e++)for(r=r<<8|t[e],n+=8;n>=5;)a+=C[r>>>n-5&31],n-=5;return n>0&&(a+=C[r<<5-n&31]),a}function E(e){let t=e.toLowerCase().replace(/=+$/g,``),n=0,r=0,i=[];for(let e of t){let t=w[e];if(t===void 0)throw Error(`Invalid base32 character "${e}" in input`);r=r<<5|t,n+=5,n>=8&&(i.push(r>>>n-8&255),n-=8)}return Uint8Array.from(i)}function D(e){let t=i.bytesFrom(e);if(t.length!==20)throw Error(`did:ckb args must be 20 bytes, got ${t.length}`);return S+T(t)}function O(e){if(!e.startsWith(S))throw Error(`Expected did:ckb:..., got "${e}"`);let t=e.slice(8);if(t.length!==32)throw Error(`did:ckb identifier must be 32 base32 chars, got ${t.length}`);let n=E(t);if(n.length!==20)throw Error(`did:ckb identifier must decode to 20 bytes, got ${n.length}`);return i.hexFrom(n)}function k(e){if(!e.startsWith(S))return!1;try{return O(e),!0}catch{return!1}}async function A(e,t){let n=await e.getKnownScript(i.KnownScript.DidCkb);return i.Script.from({codeHash:n.codeHash,hashType:n.hashType,args:t})}function j(e,t){return{did:D(t),id:t,data:h.decode(e.outputData),cell:e}}async function M(e){let t=i.hexFrom(e.id),n=await A(e.client,t),r=await e.client.findSingletonCellByType(n,!0);if(r)return j(r,t)}async function N(e){if(!k(e.did))throw Error(`Not a did:ckb identifier: ${e.did}`);return M({client:e.client,id:O(e.did)})}async function P(e){let t=await e.client.getKnownScript(i.KnownScript.DidCkb),n=[];for await(let r of e.client.findCells({script:i.Script.from(e.lock),scriptType:`lock`,scriptSearchMode:`exact`,filter:{script:i.Script.from({codeHash:t.codeHash,hashType:t.hashType,args:`0x`})},withData:!0},e.order,e.limit)){let e=r.cellOutput.type;if(e&&i.bytesFrom(e.args).length===20)try{n.push(j(r,i.hexFrom(e.args)))}catch{}}return n}async function F(e){let t=typeof e.id==`string`&&k(e.id)?O(e.id):i.hexFrom(e.id),n=(await e.client.getKnownScript(i.KnownScript.DidCkb)).codeHash.toLowerCase(),r=t.toLowerCase(),a=e.liveCell??(await M({client:e.client,id:t}))?.cell;if(!a)return[];let o=[],s=e.maxSteps??50,c=0;for(;a&&c<s;){c++;let t=await e.client.getTransaction(a.outPoint.txHash);if(!t)break;let i=L(a,t.blockNumber);if(!i)break;let s=await I(e.client,t.transaction,n,r);if(!s){i.action=i.data.value.localId?`MIGRATE`:`CREATE`,o.push(i);break}i.action=`UPDATE`,o.push(i),a=s}return o}async function I(e,t,n,r){let{inputs:a}=i.Transaction.from(t);for(let t of a){let a;try{a=await t.getCell(e)}catch{continue}let o=a.cellOutput.type;if(o&&o.codeHash.toLowerCase()===n&&i.hexFrom(o.args).toLowerCase()===r)return a}}function L(e,t){try{let n=h.decode(e.outputData);return{action:`UPDATE`,txHash:e.outPoint.txHash,outputIndex:e.outPoint.index,blockNumber:t,capacity:e.cellOutput.capacity,data:n}}catch{return}}function R(e){let r=t(e.genesisOperation);if(!r[e.rotationKeyIndex])throw Error(`rotationKeyIndex ${e.rotationKeyIndex} out of range (genesis has ${r.length} keys)`);let a=e.curve??r[e.rotationKeyIndex].curve,o=n(e.rotationPrivateKey,i.bytesFrom(e.txHash),a);return _.from({localIdAuthorization:{history:[e.genesisOperation],sig:i.hexFrom(o),rotationKeyIndices:[e.selfSigIndex??0,e.rotationKeyIndex]}})}async function z(e){if(!e.sourceDid.startsWith(`did:plc:`))throw Error(`sourceDid must be did:plc:..., got "${e.sourceDid}"`);let t=h.from(e.data??{value:{document:{}}});return t.value.localId=e.sourceDid,y({signer:e.signer,data:t,receiver:e.receiver,tx:e.tx})}var B=e({DidCkbData:()=>h,DidCkbDataV1:()=>p,DidCkbWitness:()=>_,PlcAuthorization:()=>g,argsToDid:()=>D,base32Decode:()=>E,base32Encode:()=>T,buildMigrationWitness:()=>R,createDidCkb:()=>y,destroyDidCkb:()=>x,didToArgs:()=>O,findDidCkbCell:()=>M,getDidCkbHistory:()=>F,isDidCkb:()=>k,listDidCkbsByLock:()=>P,migrateDidCkb:()=>z,plc:()=>r,resolveDidCkb:()=>N,transferDidCkb:()=>b});export{p as _,M as a,D as c,O as d,k as f,h as g,b as h,F as i,E as l,x as m,R as n,P as o,y as p,z as r,N as s,B as t,T as u,_ as v,g as y};
|
|
2
|
-
//# sourceMappingURL=barrel-DEJnxd4o.mjs.map
|