@interop/bnid 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,450 @@
1
+ /*!
2
+ * Copyright (c) 2020 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import { base58btc } from './baseX.js';
5
+ import { getRandomBytes, bytesToHex, bytesFromHex } from './util.js';
6
+ // multihash identity function code
7
+ const MULTIHASH_IDENTITY_FUNCTION_CODE = 0x00;
8
+ function _calcOptionsBitLength({ defaultLength,
9
+ // TODO: allow any bit length
10
+ minLength = 8,
11
+ // TODO: support maxLength
12
+ // maxLength = Infinity,
13
+ bitLength }) {
14
+ if (bitLength === undefined) {
15
+ return defaultLength;
16
+ }
17
+ // TODO: allow any bit length
18
+ if (bitLength % 8 !== 0) {
19
+ throw new Error('Bit length must be a multiple of 8.');
20
+ }
21
+ if (bitLength < minLength) {
22
+ throw new Error(`Minimum bit length is ${minLength}.`);
23
+ }
24
+ // TODO: support maxLength
25
+ // if(bitLength > maxLength) {
26
+ // throw new Error(`Maximum bit length is ${maxLength}.`);
27
+ // }
28
+ return bitLength;
29
+ }
30
+ function _calcDataBitLength({ bitLength, maxLength }) {
31
+ if (maxLength === 0) {
32
+ return bitLength;
33
+ }
34
+ if (maxLength && bitLength > maxLength) {
35
+ throw new Error(`Input length greater than ${maxLength} bits.`);
36
+ }
37
+ // @ts-expect-error - maxLength may be undefined when no fixed length is set
38
+ return maxLength;
39
+ }
40
+ function _bytesWithBitLength({ bytes, bitLength }) {
41
+ const length = bytes.length * 8;
42
+ if (length === bitLength) {
43
+ return bytes;
44
+ }
45
+ if (length < bitLength) {
46
+ // pad start
47
+ const data = new Uint8Array(bitLength / 8);
48
+ data.set(bytes, data.length - bytes.length);
49
+ return data;
50
+ }
51
+ // trim start, ensure trimmed data is zero
52
+ const start = (length - bitLength) / 8;
53
+ if (bytes.subarray(0, start).some(d => d !== 0)) {
54
+ throw new Error(`Data length greater than ${bitLength} bits.`);
55
+ }
56
+ return bytes.subarray(start);
57
+ }
58
+ const _log2_16 = 4;
59
+ function _base16Encoder({ bytes, idEncoder }) {
60
+ let encoded = bytesToHex(bytes);
61
+ if (idEncoder.encoding === 'base16upper') {
62
+ encoded = encoded.toUpperCase();
63
+ }
64
+ if (idEncoder.fixedLength && idEncoder.fixedLength !== undefined) {
65
+ const fixedBitLength = _calcDataBitLength({
66
+ bitLength: bytes.length * 8,
67
+ maxLength: idEncoder.fixedBitLength
68
+ });
69
+ const wantLength = Math.ceil(fixedBitLength / _log2_16);
70
+ // pad start with 0s
71
+ return encoded.padStart(wantLength, '0');
72
+ }
73
+ return encoded;
74
+ }
75
+ const _log2_58 = Math.log2(58);
76
+ function _base58Encoder({ bytes, idEncoder }) {
77
+ const encoded = base58btc.encode(bytes);
78
+ if (idEncoder.fixedLength) {
79
+ const fixedBitLength = _calcDataBitLength({
80
+ bitLength: bytes.length * 8,
81
+ maxLength: idEncoder.fixedBitLength
82
+ });
83
+ const wantLength = Math.ceil(fixedBitLength / _log2_58);
84
+ // pad start with 0s (encoded as '1's)
85
+ return encoded.padStart(wantLength, '1');
86
+ }
87
+ return encoded;
88
+ }
89
+ export class IdGenerator {
90
+ bitLength;
91
+ /**
92
+ * Creates a new IdGenerator instance.
93
+ *
94
+ * An IdGenerator generates an array of id bytes.
95
+ *
96
+ * @param {object} [options] - The options to use.
97
+ * @param {number} [options.bitLength=128] - Number of bits to generate.
98
+ *
99
+ * @returns {IdGenerator} - New IdGenerator.
100
+ */
101
+ constructor({ bitLength } = {}) {
102
+ this.bitLength = _calcOptionsBitLength({
103
+ // default to 128 bits / 16 bytes
104
+ defaultLength: 128,
105
+ // TODO: allow any bit length
106
+ minLength: 8,
107
+ bitLength
108
+ });
109
+ }
110
+ /**
111
+ * Generate random id bytes.
112
+ *
113
+ * @returns {Uint8Array} - Array of random id bytes.
114
+ */
115
+ async generate() {
116
+ const buf = new Uint8Array(this.bitLength / 8);
117
+ await getRandomBytes(buf);
118
+ return buf;
119
+ }
120
+ }
121
+ export class IdEncoder {
122
+ encoder;
123
+ encoding;
124
+ multibasePrefix;
125
+ fixedLength;
126
+ fixedBitLength;
127
+ multibase = true;
128
+ multihash = false;
129
+ /**
130
+ * Creates a new IdEncoder instance.
131
+ *
132
+ * An IdEncoder encodes an array of id bytes into a specific encoding.
133
+ *
134
+ * @param {object} [options] - The options to use.
135
+ * @param {string} [options.encoding='base58'] - Encoding format.
136
+ * @param {boolean} [options.fixedLength=false] - `true` to ensure fixed
137
+ * output length.
138
+ * @param {number} [options.fixedBitLength] - Fixed output bit length or 0 to
139
+ * base on input byte size.
140
+ * @param {boolean} [options.multibase=true] - Use multibase encoding.
141
+ * @param {boolean} [options.multihash=false] - Use multihash encoding.
142
+ *
143
+ * @returns {IdEncoder} - New IdEncoder.
144
+ */
145
+ constructor({ encoding = 'base58', fixedLength = false, fixedBitLength, multibase = true, multihash = false } = {}) {
146
+ switch (encoding) {
147
+ case 'hex':
148
+ case 'base16':
149
+ this.encoder = _base16Encoder;
150
+ this.multibasePrefix = 'f';
151
+ break;
152
+ case 'base16upper':
153
+ this.encoder = _base16Encoder;
154
+ this.multibasePrefix = 'F';
155
+ break;
156
+ case 'base58':
157
+ case 'base58btc':
158
+ this.encoder = _base58Encoder;
159
+ this.multibasePrefix = 'z';
160
+ break;
161
+ default:
162
+ throw new Error(`Unknown encoding type: "${encoding}".`);
163
+ }
164
+ this.fixedLength = fixedLength || fixedBitLength !== undefined;
165
+ if (this.fixedLength) {
166
+ this.fixedBitLength = _calcOptionsBitLength({
167
+ // default of 0 calculates from input size
168
+ defaultLength: 0,
169
+ bitLength: fixedBitLength
170
+ });
171
+ }
172
+ this.encoding = encoding;
173
+ this.multibase = multibase;
174
+ this.multihash = multihash;
175
+ }
176
+ /**
177
+ * Encode id bytes into a string.
178
+ *
179
+ * @param {Uint8Array} bytes - Bytes to encode.
180
+ *
181
+ * @returns {string} - Encoded string.
182
+ */
183
+ encode(bytes) {
184
+ if (this.multihash) {
185
+ const byteSize = bytes.length;
186
+ if (byteSize > 127) {
187
+ throw new RangeError('Identifier size too large.');
188
+ }
189
+ // <varint hash fn code> <varint digest size in bytes> <hash fn output>
190
+ // <identity function> <byte size> <raw bytes>
191
+ const multihash = new Uint8Array(2 + byteSize);
192
+ // <varint hash fn code>: identity function
193
+ multihash.set([MULTIHASH_IDENTITY_FUNCTION_CODE]);
194
+ // <varint digest size in bytes>
195
+ multihash.set([byteSize], 1);
196
+ // <hash fn output>: identifier bytes
197
+ multihash.set(bytes, 2);
198
+ bytes = multihash;
199
+ }
200
+ const encoded = this.encoder({ bytes, idEncoder: this });
201
+ if (this.multibase) {
202
+ return this.multibasePrefix + encoded;
203
+ }
204
+ return encoded;
205
+ }
206
+ }
207
+ export class IdDecoder {
208
+ encoding;
209
+ fixedBitLength = 0;
210
+ multibase;
211
+ multihash;
212
+ expectedSize;
213
+ /**
214
+ * Creates a new IdDecoder instance.
215
+ *
216
+ * An IdDecoder decodes an id string into a byte array. It is recommended to
217
+ * use the fixedBitLength option to avoid padding ids resulting in a larger
218
+ * than expected byte length.
219
+ *
220
+ * @param {object} [options] - The options to use.
221
+ * @param {string} [options.encoding='base58'] - Encoding format. Ignored if
222
+ * multibase is true.
223
+ * @param {number} [options.fixedBitLength] - Fixed output bit length. Values
224
+ * with leading non-zero data will error.
225
+ * @param {boolean} [options.multibase=true] - Use multibase encoding to
226
+ * detect the id format.
227
+ * @param {boolean} [options.multihash=false] - Use multihash encoding to
228
+ * detect the id format.
229
+ * @param {number} [options.expectedSize=32] - Optional expected identifier
230
+ * size in bytes (only for multihash encoding). Use `0` to disable size
231
+ * check.
232
+ * @returns {IdDecoder} - New IdDecoder.
233
+ */
234
+ constructor({ encoding = 'base58', fixedBitLength = 0, multibase = true, multihash = false, expectedSize = 32 } = {}) {
235
+ this.encoding = encoding;
236
+ this.fixedBitLength = fixedBitLength;
237
+ this.multibase = multibase;
238
+ this.multihash = multihash;
239
+ this.expectedSize = expectedSize;
240
+ }
241
+ /**
242
+ * Decode id string into bytes.
243
+ *
244
+ * @param {string} id - Id to decode.
245
+ *
246
+ * @returns {Uint8Array} - Array of decoded id bytes.
247
+ */
248
+ decode(id) {
249
+ let encoding;
250
+ let data;
251
+ if (this.multibase) {
252
+ if (id.length < 1) {
253
+ throw new Error('Multibase encoding not found.');
254
+ }
255
+ const prefix = id[0];
256
+ data = id.substring(1);
257
+ switch (id[0]) {
258
+ case 'f':
259
+ encoding = 'base16';
260
+ break;
261
+ case 'F':
262
+ encoding = 'base16upper';
263
+ break;
264
+ case 'z':
265
+ encoding = 'base58';
266
+ break;
267
+ default:
268
+ throw new Error(`Unknown multibase prefix "${prefix}".`);
269
+ }
270
+ }
271
+ else {
272
+ encoding = this.encoding;
273
+ data = id;
274
+ }
275
+ let decoded;
276
+ switch (encoding) {
277
+ case 'hex':
278
+ case 'base16':
279
+ case 'base16upper':
280
+ if (data.length % 2 !== 0) {
281
+ throw new Error('Invalid base16 data length.');
282
+ }
283
+ decoded = bytesFromHex(data);
284
+ break;
285
+ case 'base58':
286
+ decoded = base58btc.decode(data);
287
+ break;
288
+ default:
289
+ throw new Error(`Unknown encoding "${encoding}".`);
290
+ }
291
+ if (!decoded) {
292
+ throw new Error(`Invalid encoded data "${data}".`);
293
+ }
294
+ if (this.fixedBitLength) {
295
+ return _bytesWithBitLength({
296
+ bytes: decoded,
297
+ bitLength: this.fixedBitLength ?? 0
298
+ });
299
+ }
300
+ if (this.multihash) {
301
+ // <varint hash fn code>: identity function
302
+ const [hashFnCode] = decoded;
303
+ if (hashFnCode !== MULTIHASH_IDENTITY_FUNCTION_CODE) {
304
+ throw new Error('Invalid multihash function code.');
305
+ }
306
+ // <varint digest size in bytes>
307
+ const digestSize = decoded[1];
308
+ if (digestSize > 127) {
309
+ throw new RangeError('Decoded identifier size too large.');
310
+ }
311
+ const bytes = decoded.subarray(2);
312
+ if (bytes.byteLength !== digestSize) {
313
+ throw new RangeError('Unexpected identifier size.');
314
+ }
315
+ if (this.expectedSize && bytes.byteLength !== this.expectedSize) {
316
+ throw new RangeError('Invalid decoded identifier size. Identifier must be ' +
317
+ `"${this.expectedSize}" bytes.`);
318
+ }
319
+ decoded = bytes;
320
+ }
321
+ return decoded;
322
+ }
323
+ }
324
+ /**
325
+ * Generates an encoded id string from random bits.
326
+ *
327
+ * @param {object} [options] - The options to use. See `IdEncoder` and
328
+ * `IdGenerator` for available options.
329
+ *
330
+ * @returns {string} - Encoded string id.
331
+ */
332
+ export async function generateId(options) {
333
+ return new IdEncoder(options).encode(await new IdGenerator(options).generate());
334
+ }
335
+ /**
336
+ * Decodes an encoded id string to an array of bytes.
337
+ *
338
+ * @param {object} options - The options to use. See `IdDecoder` for available
339
+ * options.
340
+ * @param {string} options.id - Id to decode.
341
+ *
342
+ * @returns {Uint8Array} - Decoded array of id bytes.
343
+ */
344
+ export function decodeId(options) {
345
+ return new IdDecoder(options).decode(options.id);
346
+ }
347
+ /**
348
+ * Minimum number of bytes needed to encode an id of a given bit length.
349
+ *
350
+ * @param {object} options - The options to use.
351
+ * @param {string} [options.encoding='base58'] - Encoding format.
352
+ * @param {number} [options.bitLength=128] - Number of id bits.
353
+ * @param {boolean} [options.multibase=true] - Account for multibase encoding.
354
+ *
355
+ * @returns {number} - The minimum number of encoded bytes.
356
+ */
357
+ export function minEncodedIdBytes({ encoding = 'base58', bitLength = 128, multibase = true } = {}) {
358
+ let plainBytes;
359
+ switch (encoding) {
360
+ case 'hex':
361
+ case 'base16':
362
+ case 'base16upper':
363
+ plainBytes = bitLength / 4;
364
+ break;
365
+ case 'base58':
366
+ case 'base58btc':
367
+ plainBytes = bitLength / 8;
368
+ break;
369
+ default:
370
+ throw new Error(`Unknown encoding type: "${encoding}".`);
371
+ }
372
+ return plainBytes + (multibase ? 1 : 0);
373
+ }
374
+ /**
375
+ * Maximum number of bytes needed to encode an id of a given bit length.
376
+ *
377
+ * @param {object} options - The options to use.
378
+ * @param {string} [options.encoding='base58'] - Encoding format.
379
+ * @param {number} [options.bitLength=128] - Number of id bits.
380
+ * @param {boolean} [options.multibase=true] - Account for multibase encoding.
381
+ *
382
+ * @returns {number} - The maximum number of encoded bytes.
383
+ */
384
+ export function maxEncodedIdBytes({ encoding = 'base58', bitLength = 128, multibase = true } = {}) {
385
+ let plainBytes;
386
+ switch (encoding) {
387
+ case 'hex':
388
+ case 'base16':
389
+ case 'base16upper':
390
+ plainBytes = bitLength / 4;
391
+ break;
392
+ case 'base58':
393
+ case 'base58btc':
394
+ plainBytes = Math.ceil(bitLength / Math.log2(58));
395
+ break;
396
+ default:
397
+ throw new Error(`Unknown encoding type: "${encoding}".`);
398
+ }
399
+ return plainBytes + (multibase ? 1 : 0);
400
+ }
401
+ /**
402
+ * Generates a secret key seed encoded as a string that can be stored and later
403
+ * used to generate a key pair. The public key from the key pair can be used as
404
+ * an identifier. The key seed (both raw and encoded form) MUST be kept secret.
405
+ *
406
+ * @param {object} [options] - The options to use.
407
+ * @param {string} [options.encoding='base58'] - Encoding format.
408
+ * @param {number} [options.bitLength=32 * 8] - Number of bits to generate.
409
+ * @param {boolean} [options.multibase=true] - Use multibase encoding.
410
+ * @param {boolean} [options.multihash=true] - Use multihash encoding.
411
+
412
+ * @returns {string} - Secret key seed encoded as a string.
413
+ */
414
+ export async function generateSecretKeySeed({ bitLength = 32 * 8, encoding = 'base58', multibase = true, multihash = true } = {}) {
415
+ // reuse `generateId` for convenience, but a key seed is *SECRET* and
416
+ // not an identifier itself, rather it is used to generate an identifier via
417
+ // a public key
418
+ // Note: Setting fixedLength to false even though that's the (current)
419
+ // default as not using a fixed length of false for a seed is a security
420
+ // problem
421
+ return await generateId({
422
+ bitLength,
423
+ encoding,
424
+ fixedLength: false,
425
+ multibase,
426
+ multihash
427
+ });
428
+ }
429
+ /**
430
+ * Decodes an encoded secret key seed into an array of secret key seed bytes.
431
+ * The key seed bytes MUST be kept secret.
432
+ *
433
+ * @param {object} options - The options to use.
434
+ * @param {boolean} [options.multibase=true] - Use multibase encoding to detect
435
+ * the id format.
436
+ * @param {boolean} [options.multihash=true] - Use multihash encoding to detect
437
+ * the id format.
438
+ * @param {number} [options.expectedSize] - Optional expected identifier size
439
+ * in bytes (only for multihash encoding). Use `0` to disable size check.
440
+ * @param {string} options.secretKeySeed - The secret key seed to be decoded.
441
+ *
442
+ * @returns {Uint8Array} - An array of secret key seed bytes (default size:
443
+ * 32 bytes).
444
+ */
445
+ export function decodeSecretKeySeed({ multibase = true, multihash = true, expectedSize = 32, secretKeySeed }) {
446
+ // reuse `decodeId` for convenience, but key seed bytes are *SECRET* and
447
+ // are NOT identifiers, they are used to generate identifiers from public keys
448
+ return decodeId({ multihash, multibase, expectedSize, id: secretKeySeed });
449
+ }
450
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAEpE,mCAAmC;AACnC,MAAM,gCAAgC,GAAG,IAAI,CAAA;AAE7C,SAAS,qBAAqB,CAAC,EAC7B,aAAa;AACb,6BAA6B;AAC7B,SAAS,GAAG,CAAC;AACb,0BAA0B;AAC1B,wBAAwB;AACxB,SAAS,EAKV;IACC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO,aAAa,CAAA;IACtB,CAAC;IACD,6BAA6B;IAC7B,IAAI,SAAS,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;IACxD,CAAC;IACD,IAAI,SAAS,GAAG,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,yBAAyB,SAAS,GAAG,CAAC,CAAA;IACxD,CAAC;IACD,0BAA0B;IAC1B,8BAA8B;IAC9B,2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;IACxE,UAAU;IACV,OAAO,MAAM,UAAU,CAAC;QACtB,SAAS;QACT,QAAQ;QACR,WAAW,EAAE,KAAK;QAClB,SAAS;QACT,SAAS;KACV,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,SAAS,GAAG,IAAI,EAChB,SAAS,GAAG,IAAI,EAChB,YAAY,GAAG,EAAE,EACjB,aAAa,EAMd;IACC,wEAAwE;IACxE,8EAA8E;IAC9E,OAAO,QAAQ,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,EAAE,EAAE,aAAa,EAAE,CAAC,CAAA;AAC5E,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function getRandomBytes(buf: Uint8Array): Promise<Uint8Array>;
2
+ export declare function bytesToHex(bytes: Uint8Array): string;
3
+ export declare function bytesFromHex(hex: string): Uint8Array;
4
+ //# sourceMappingURL=util-browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util-browser.d.ts","sourceRoot":"","sources":["../src/util-browser.ts"],"names":[],"mappings":"AAGA,wBAAsB,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAEzE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIpD;AAKD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAMpD"}
@@ -0,0 +1,20 @@
1
+ // browser support
2
+ const crypto = globalThis.crypto;
3
+ export async function getRandomBytes(buf) {
4
+ return crypto.getRandomValues(buf);
5
+ }
6
+ export function bytesToHex(bytes) {
7
+ return Array.from(bytes)
8
+ .map(d => d.toString(16).padStart(2, '0'))
9
+ .join('');
10
+ }
11
+ // adapted from:
12
+ // https://stackoverflow.com/questions/43131242/how-to-convert-a-hexadecimal-string-of-data-to-an-arraybuffer-in-javascript
13
+ export function bytesFromHex(hex) {
14
+ if (hex.length === 0) {
15
+ return new Uint8Array();
16
+ }
17
+ // @ts-expect-error - match() is non-null for validated hex input
18
+ return new Uint8Array(hex.match(/[\da-f]{2}/gi).map(h => parseInt(h, 16)));
19
+ }
20
+ //# sourceMappingURL=util-browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util-browser.js","sourceRoot":"","sources":["../src/util-browser.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAClB,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAA;AAEhC,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAe;IAClD,OAAO,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;AACpC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAiB;IAC1C,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;SACrB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SACzC,IAAI,CAAC,EAAE,CAAC,CAAA;AACb,CAAC;AAED,gBAAgB;AAEhB,2HAA2H;AAC3H,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,IAAI,UAAU,EAAE,CAAA;IACzB,CAAC;IACD,iEAAiE;IACjE,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;AAC5E,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function getRandomBytes(buf: Uint8Array): Promise<Uint8Array>;
2
+ export declare function bytesToHex(bytes: Uint8Array): string;
3
+ export declare function bytesFromHex(hex: string): Uint8Array;
4
+ //# sourceMappingURL=util-reactnative.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util-reactnative.d.ts","sourceRoot":"","sources":["../src/util-reactnative.ts"],"names":[],"mappings":"AAOA,wBAAsB,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAEzE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIpD;AAKD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAMpD"}
@@ -0,0 +1,24 @@
1
+ // React Native support
2
+ //
3
+ // Requires the `react-native-get-random-values` polyfill, imported once at the
4
+ // top of the app entry, so that `globalThis.crypto.getRandomValues()` is
5
+ // available. See the README "React Native" section.
6
+ const crypto = globalThis.crypto;
7
+ export async function getRandomBytes(buf) {
8
+ return crypto.getRandomValues(buf);
9
+ }
10
+ export function bytesToHex(bytes) {
11
+ return Array.from(bytes)
12
+ .map(d => d.toString(16).padStart(2, '0'))
13
+ .join('');
14
+ }
15
+ // adapted from:
16
+ // https://stackoverflow.com/questions/43131242/how-to-convert-a-hexadecimal-string-of-data-to-an-arraybuffer-in-javascript
17
+ export function bytesFromHex(hex) {
18
+ if (hex.length === 0) {
19
+ return new Uint8Array();
20
+ }
21
+ // @ts-expect-error - match() is non-null for validated hex input
22
+ return new Uint8Array(hex.match(/[\da-f]{2}/gi).map(h => parseInt(h, 16)));
23
+ }
24
+ //# sourceMappingURL=util-reactnative.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util-reactnative.js","sourceRoot":"","sources":["../src/util-reactnative.ts"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,EAAE;AACF,+EAA+E;AAC/E,yEAAyE;AACzE,oDAAoD;AACpD,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAA;AAEhC,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAe;IAClD,OAAO,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;AACpC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAiB;IAC1C,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;SACrB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SACzC,IAAI,CAAC,EAAE,CAAC,CAAA;AACb,CAAC;AAED,gBAAgB;AAEhB,2HAA2H;AAC3H,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,IAAI,UAAU,EAAE,CAAA;IACzB,CAAC;IACD,iEAAiE;IACjE,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;AAC5E,CAAC"}
package/dist/util.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare function getRandomBytes(buf: Uint8Array): Promise<unknown>;
2
+ export declare function bytesToHex(bytes: Uint8Array): string;
3
+ export declare function bytesFromHex(hex: string): Uint8Array;
4
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAMA,wBAAsB,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAEtE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEpD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAEpD"}
package/dist/util.js ADDED
@@ -0,0 +1,14 @@
1
+ // Node.js support
2
+ import * as crypto from 'crypto';
3
+ import { promisify } from 'util';
4
+ const randomFill = promisify(crypto.randomFill);
5
+ export async function getRandomBytes(buf) {
6
+ return await randomFill(buf);
7
+ }
8
+ export function bytesToHex(bytes) {
9
+ return Buffer.from(bytes).toString('hex');
10
+ }
11
+ export function bytesFromHex(hex) {
12
+ return new Uint8Array(Buffer.from(hex, 'hex'));
13
+ }
14
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAClB,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAEhC,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;AAE/C,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAe;IAClD,OAAO,MAAM,UAAU,CAAC,GAAG,CAAC,CAAA;AAC9B,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAiB;IAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAC3C,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;AAChD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,103 @@
1
+ {
2
+ "name": "@interop/bnid",
3
+ "version": "6.0.0",
4
+ "description": "Base-N Id Generator",
5
+ "license": "BSD-3-Clause",
6
+ "scripts": {
7
+ "build": "pnpm run clear && tsc",
8
+ "clear": "rimraf dist/*",
9
+ "dev": "vite",
10
+ "fix": "eslint --fix src test && pnpm run format",
11
+ "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"*.md\"",
12
+ "lint": "eslint src test",
13
+ "prepare": "pnpm run build",
14
+ "rebuild": "pnpm run clear && pnpm run build",
15
+ "test": "pnpm run fix && pnpm run lint && pnpm run test:node && pnpm run test:browser",
16
+ "test:browser": "playwright test",
17
+ "test:node": "vitest run",
18
+ "test:coverage": "vitest run --coverage"
19
+ },
20
+ "homepage": "https://github.com/interop-alliance/bnid",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/interop-alliance/bnid.git"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/interop-alliance/bnid/issues"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "src",
31
+ "CHANGELOG.md",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "type": "module",
36
+ "module": "./dist/index.js",
37
+ "types": "./dist/index.d.ts",
38
+ "exports": {
39
+ ".": {
40
+ "types": "./dist/index.d.ts",
41
+ "import": "./dist/index.js",
42
+ "default": "./dist/index.js"
43
+ }
44
+ },
45
+ "sideEffects": false,
46
+ "dependencies": {
47
+ "@scure/base": "^2.2.0"
48
+ },
49
+ "peerDependencies": {
50
+ "react-native-get-random-values": ">=1.8.0"
51
+ },
52
+ "peerDependenciesMeta": {
53
+ "react-native-get-random-values": {
54
+ "optional": true
55
+ }
56
+ },
57
+ "devDependencies": {
58
+ "@eslint/js": "^10.0.1",
59
+ "@playwright/test": "^1.60.0",
60
+ "@types/node": "^25.9.1",
61
+ "@vitest/coverage-v8": "^4.1.7",
62
+ "eslint": "^10.4.0",
63
+ "eslint-config-prettier": "^10.1.8",
64
+ "globals": "^17.6.0",
65
+ "prettier": "^3.8.3",
66
+ "rimraf": "^6.1.3",
67
+ "typescript": "^5.9.3",
68
+ "typescript-eslint": "^8.59.4",
69
+ "vite": "^8.0.14",
70
+ "vitest": "^4.1.7"
71
+ },
72
+ "publishConfig": {
73
+ "access": "public"
74
+ },
75
+ "browser": {
76
+ "./src/util.ts": "./src/util-browser.ts",
77
+ "./dist/util.js": "./dist/util-browser.js",
78
+ "buffer": false,
79
+ "crypto": false,
80
+ "util": false
81
+ },
82
+ "react-native": {
83
+ "buffer": false,
84
+ "crypto": false,
85
+ "util": false,
86
+ "./src/util.ts": "./src/util-reactnative.ts",
87
+ "./dist/util.js": "./dist/util-reactnative.js"
88
+ },
89
+ "packageManager": "pnpm@11.5.0",
90
+ "engines": {
91
+ "node": ">=24.0"
92
+ },
93
+ "keywords": [
94
+ "id",
95
+ "identifier",
96
+ "random"
97
+ ],
98
+ "author": {
99
+ "name": "Digital Bazaar, Inc.",
100
+ "email": "support@digitalbazaar.com",
101
+ "url": "https://digitalbazaar.com/"
102
+ }
103
+ }