@metamask/utils 11.6.0 → 11.8.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/CHANGELOG.md +19 -1
- package/dist/bytes.cjs +28 -1
- package/dist/bytes.cjs.map +1 -1
- package/dist/bytes.d.cts +15 -0
- package/dist/bytes.d.cts.map +1 -1
- package/dist/bytes.d.mts +15 -0
- package/dist/bytes.d.mts.map +1 -1
- package/dist/bytes.mjs +26 -0
- package/dist/bytes.mjs.map +1 -1
- package/dist/caip-types.cjs +2 -0
- package/dist/caip-types.cjs.map +1 -1
- package/dist/caip-types.d.cts +2 -0
- package/dist/caip-types.d.cts.map +1 -1
- package/dist/caip-types.d.mts +2 -0
- package/dist/caip-types.d.mts.map +1 -1
- package/dist/caip-types.mjs +2 -0
- package/dist/caip-types.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [11.8.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `areUint8ArraysEqual` function to compare two `Uint8Array` types ([#268](https://github.com/MetaMask/utils/pull/268))
|
|
15
|
+
|
|
16
|
+
## [11.7.0]
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- Add Tron CAIP namespace ([#266](https://github.com/MetaMask/utils/pull/266))
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- Fix API docs generation ([#264](https://github.com/MetaMask/utils/pull/264))
|
|
25
|
+
|
|
10
26
|
## [11.6.0]
|
|
11
27
|
|
|
12
28
|
### Added
|
|
@@ -451,7 +467,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
451
467
|
|
|
452
468
|
- Initial release
|
|
453
469
|
|
|
454
|
-
[Unreleased]: https://github.com/MetaMask/utils/compare/v11.
|
|
470
|
+
[Unreleased]: https://github.com/MetaMask/utils/compare/v11.8.0...HEAD
|
|
471
|
+
[11.8.0]: https://github.com/MetaMask/utils/compare/v11.7.0...v11.8.0
|
|
472
|
+
[11.7.0]: https://github.com/MetaMask/utils/compare/v11.6.0...v11.7.0
|
|
455
473
|
[11.6.0]: https://github.com/MetaMask/utils/compare/v11.5.0...v11.6.0
|
|
456
474
|
[11.5.0]: https://github.com/MetaMask/utils/compare/v11.4.2...v11.5.0
|
|
457
475
|
[11.4.2]: https://github.com/MetaMask/utils/compare/v11.4.1...v11.4.2
|
package/dist/bytes.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDataView = exports.concatBytes = exports.valueToBytes = exports.base64ToBytes = exports.stringToBytes = exports.numberToBytes = exports.signedBigIntToBytes = exports.bigIntToBytes = exports.hexToBytes = exports.bytesToBase64 = exports.bytesToString = exports.bytesToNumber = exports.bytesToSignedBigInt = exports.bytesToBigInt = exports.bytesToHex = exports.assertIsBytes = exports.isBytes = void 0;
|
|
3
|
+
exports.areUint8ArraysEqual = exports.createDataView = exports.concatBytes = exports.valueToBytes = exports.base64ToBytes = exports.stringToBytes = exports.numberToBytes = exports.signedBigIntToBytes = exports.bigIntToBytes = exports.hexToBytes = exports.bytesToBase64 = exports.bytesToString = exports.bytesToNumber = exports.bytesToSignedBigInt = exports.bytesToBigInt = exports.bytesToHex = exports.assertIsBytes = exports.isBytes = void 0;
|
|
4
4
|
const base_1 = require("@scure/base");
|
|
5
5
|
const assert_1 = require("./assert.cjs");
|
|
6
6
|
const hex_1 = require("./hex.cjs");
|
|
@@ -397,4 +397,31 @@ function createDataView(bytes) {
|
|
|
397
397
|
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
398
398
|
}
|
|
399
399
|
exports.createDataView = createDataView;
|
|
400
|
+
/**
|
|
401
|
+
* Compare two Uint8Arrays using a constant-time style loop to reduce timing
|
|
402
|
+
* side-channels when comparing sensitive data (e.g., mnemonic bytes, keys,
|
|
403
|
+
* authentication tags). Does not early-return on the first difference:
|
|
404
|
+
* work done depends only on the input lengths, so byte content does not affect timing.
|
|
405
|
+
*
|
|
406
|
+
* When to use:
|
|
407
|
+
* - Use for secret or security-sensitive byte comparisons to avoid content-based timing leaks.
|
|
408
|
+
* - Prefer when inputs are fixed-length (or validated to equal length) at the API boundary.
|
|
409
|
+
*
|
|
410
|
+
* @param a - The first Uint8Array to compare.
|
|
411
|
+
* @param b - The second Uint8Array to compare.
|
|
412
|
+
* @returns Whether the Uint8Arrays are equal.
|
|
413
|
+
*/
|
|
414
|
+
function areUint8ArraysEqual(a, b) {
|
|
415
|
+
// eslint-disable-next-line no-bitwise
|
|
416
|
+
let diff = a.byteLength ^ b.byteLength;
|
|
417
|
+
const len = Math.max(a.byteLength, b.byteLength);
|
|
418
|
+
for (let i = 0; i < len; i++) {
|
|
419
|
+
const aByte = a[i] ?? 0;
|
|
420
|
+
const bByte = b[i] ?? 0;
|
|
421
|
+
// eslint-disable-next-line no-bitwise
|
|
422
|
+
diff |= aByte ^ bByte;
|
|
423
|
+
}
|
|
424
|
+
return diff === 0;
|
|
425
|
+
}
|
|
426
|
+
exports.areUint8ArraysEqual = areUint8ArraysEqual;
|
|
400
427
|
//# sourceMappingURL=bytes.cjs.map
|
package/dist/bytes.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes.cjs","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":";;;AAAA,sCAAqC;AAErC,yCAAkC;AAElC,mCAA2D;AAE3D,2BAA2B;AAC3B,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAExC,2BAA2B;AAC3B,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,MAAM,oBAAoB,GAAG,EAAE,CAAC;A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M,CAAC;KAC5B;IAED,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;IACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC5D,gEAAgE;QAChE,uEAAuE;QACvE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACvC,MAAM,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;KACtC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AArBD,kCAqBC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,cAAc,CAAC,KAAiB;IAC9C,4EAA4E;IAC5E,qEAAqE;IACrE,eAAe;IACf,iDAAiD;IACjD,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,KAAK,YAAY,MAAM,EAAE;QAC5D,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAC/B,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CACpC,CAAC;QAEF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;KAC7B;IAED,OAAO,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;AACxE,CAAC;AAfD,wCAeC","sourcesContent":["import { base64 } from '@scure/base';\n\nimport { assert } from './assert';\nimport type { Hex } from './hex';\nimport { add0x, assertIsHexString, remove0x } from './hex';\n\n// '0'.charCodeAt(0) === 48\nconst HEX_MINIMUM_NUMBER_CHARACTER = 48;\n\n// '9'.charCodeAt(0) === 57\nconst HEX_MAXIMUM_NUMBER_CHARACTER = 58;\nconst HEX_CHARACTER_OFFSET = 87;\n\nexport type Bytes = bigint | number | string | Uint8Array;\n\n/**\n * Memoized function that returns an array to be used as a lookup table for\n * converting bytes to hexadecimal values.\n *\n * The array is created lazily and then cached for future use. The benefit of\n * this approach is that the performance of converting bytes to hex is much\n * better than if we were to call `toString(16)` on each byte.\n *\n * The downside is that the array is created once and then never garbage\n * collected. This is not a problem in practice because the array is only 256\n * elements long.\n *\n * @returns A function that returns the lookup table.\n */\nfunction getPrecomputedHexValuesBuilder(): () => string[] {\n // To avoid issues with tree shaking, we need to use a function to return the\n // array. This is because the array is only used in the `bytesToHex` function\n // and if we were to use a global variable, the array might be removed by the\n // tree shaker.\n const lookupTable: string[] = [];\n\n return () => {\n if (lookupTable.length === 0) {\n for (let i = 0; i < 256; i++) {\n lookupTable.push(i.toString(16).padStart(2, '0'));\n }\n }\n\n return lookupTable;\n };\n}\n\n/**\n * Function implementation of the {@link getPrecomputedHexValuesBuilder}\n * function.\n */\nconst getPrecomputedHexValues = getPrecomputedHexValuesBuilder();\n\n/**\n * Check if a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @returns Whether the value is a `Uint8Array`.\n */\nexport function isBytes(value: unknown): value is Uint8Array {\n return value instanceof Uint8Array;\n}\n\n/**\n * Assert that a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @throws If the value is not a `Uint8Array`.\n */\nexport function assertIsBytes(value: unknown): asserts value is Uint8Array {\n assert(isBytes(value), 'Value must be a Uint8Array.');\n}\n\n/**\n * Convert a `Uint8Array` to a hexadecimal string.\n *\n * @param bytes - The bytes to convert to a hexadecimal string.\n * @returns The hexadecimal string.\n */\nexport function bytesToHex(bytes: Uint8Array): Hex {\n assertIsBytes(bytes);\n\n if (bytes.length === 0) {\n return '0x';\n }\n\n const lookupTable = getPrecomputedHexValues();\n const hexadecimal = new Array(bytes.length);\n\n for (let i = 0; i < bytes.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n hexadecimal[i] = lookupTable[bytes[i]!];\n }\n\n return add0x(hexadecimal.join(''));\n}\n\n/**\n * Convert a `Uint8Array` to a `bigint`.\n *\n * To convert a `Uint8Array` to a `number` instead, use {@link bytesToNumber}.\n * To convert a two's complement encoded `Uint8Array` to a `bigint`, use\n * {@link bytesToSignedBigInt}.\n *\n * @param bytes - The bytes to convert to a `bigint`.\n * @returns The `bigint`.\n */\nexport function bytesToBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n const hexadecimal = bytesToHex(bytes);\n return BigInt(hexadecimal);\n}\n\n/**\n * Convert a `Uint8Array` to a signed `bigint`. This assumes that the bytes are\n * encoded in two's complement.\n *\n * To convert a `Uint8Array` to an unsigned `bigint` instead, use\n * {@link bytesToBigInt}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param bytes - The bytes to convert to a signed `bigint`.\n * @returns The signed `bigint`.\n */\nexport function bytesToSignedBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n let value = BigInt(0);\n for (const byte of bytes) {\n // eslint-disable-next-line no-bitwise\n value = (value << BigInt(8)) + BigInt(byte);\n }\n\n return BigInt.asIntN(bytes.length * 8, value);\n}\n\n/**\n * Convert a `Uint8Array` to a `number`.\n *\n * To convert a `Uint8Array` to a `bigint` instead, use {@link bytesToBigInt}.\n *\n * @param bytes - The bytes to convert to a number.\n * @returns The number.\n * @throws If the resulting number is not a safe integer.\n */\nexport function bytesToNumber(bytes: Uint8Array): number {\n assertIsBytes(bytes);\n\n const bigint = bytesToBigInt(bytes);\n\n assert(\n bigint <= BigInt(Number.MAX_SAFE_INTEGER),\n 'Number is not a safe integer. Use `bytesToBigInt` instead.',\n );\n\n return Number(bigint);\n}\n\n/**\n * Convert a UTF-8 encoded `Uint8Array` to a `string`.\n *\n * @param bytes - The bytes to convert to a string.\n * @returns The string.\n */\nexport function bytesToString(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return new TextDecoder().decode(bytes);\n}\n\n/**\n * Convert a `Uint8Array` to a base64 encoded string.\n *\n * @param bytes - The bytes to convert to a base64 encoded string.\n * @returns The base64 encoded string.\n */\nexport function bytesToBase64(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return base64.encode(bytes);\n}\n\n/**\n * Convert a hexadecimal string to a `Uint8Array`. The string can optionally be\n * prefixed with `0x`. It accepts even and odd length strings.\n *\n * If the value is \"0x\", an empty `Uint8Array` is returned.\n *\n * @param value - The hexadecimal string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function hexToBytes(value: string): Uint8Array {\n // \"0x\" is often used as empty byte array.\n if (value?.toLowerCase?.() === '0x') {\n return new Uint8Array();\n }\n\n assertIsHexString(value);\n\n // Remove the `0x` prefix if it exists, and pad the string to have an even\n // number of characters.\n const strippedValue = remove0x(value).toLowerCase();\n const normalizedValue =\n strippedValue.length % 2 === 0 ? strippedValue : `0${strippedValue}`;\n const bytes = new Uint8Array(normalizedValue.length / 2);\n\n for (let i = 0; i < bytes.length; i++) {\n // While this is not the prettiest way to convert a hexadecimal string to a\n // `Uint8Array`, it is a lot faster than using `parseInt` to convert each\n // character.\n const c1 = normalizedValue.charCodeAt(i * 2);\n const c2 = normalizedValue.charCodeAt(i * 2 + 1);\n const n1 =\n c1 -\n (c1 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n const n2 =\n c2 -\n (c2 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n\n bytes[i] = n1 * 16 + n2;\n }\n\n return bytes;\n}\n\n/**\n * Convert a `bigint` to a `Uint8Array`.\n *\n * This assumes that the `bigint` is an unsigned integer. To convert a signed\n * `bigint` instead, use {@link signedBigIntToBytes}.\n *\n * @param value - The bigint to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function bigIntToBytes(value: bigint): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= BigInt(0), 'Value must be a non-negative bigint.');\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Check if a `bigint` fits in a certain number of bytes.\n *\n * @param value - The `bigint` to check.\n * @param bytes - The number of bytes.\n * @returns Whether the `bigint` fits in the number of bytes.\n */\nfunction bigIntFits(value: bigint, bytes: number): boolean {\n assert(bytes > 0);\n\n /* eslint-disable no-bitwise */\n const mask = value >> BigInt(31);\n return !(((~value & mask) + (value & ~mask)) >> BigInt(bytes * 8 + ~0));\n /* eslint-enable no-bitwise */\n}\n\n/**\n * Convert a signed `bigint` to a `Uint8Array`. This uses two's complement\n * encoding to represent negative numbers.\n *\n * To convert an unsigned `bigint` to a `Uint8Array` instead, use\n * {@link bigIntToBytes}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param value - The number to convert to bytes.\n * @param byteLength - The length of the resulting `Uint8Array`. If the number\n * is larger than the maximum value that can be represented by the given length,\n * an error is thrown.\n * @returns The bytes as `Uint8Array`.\n */\nexport function signedBigIntToBytes(\n value: bigint,\n byteLength: number,\n): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(typeof byteLength === 'number', 'Byte length must be a number.');\n assert(byteLength > 0, 'Byte length must be greater than 0.');\n assert(\n bigIntFits(value, byteLength),\n 'Byte length is too small to represent the given value.',\n );\n\n // ESLint doesn't like mutating function parameters, so to avoid having to\n // disable the rule, we create a new variable.\n let numberValue = value;\n const bytes = new Uint8Array(byteLength);\n\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Number(BigInt.asUintN(8, numberValue));\n // eslint-disable-next-line no-bitwise\n numberValue >>= BigInt(8);\n }\n\n return bytes.reverse();\n}\n\n/**\n * Convert a `number` to a `Uint8Array`.\n *\n * @param value - The number to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n * @throws If the number is not a safe integer.\n */\nexport function numberToBytes(value: number): Uint8Array {\n assert(typeof value === 'number', 'Value must be a number.');\n assert(value >= 0, 'Value must be a non-negative number.');\n assert(\n Number.isSafeInteger(value),\n 'Value is not a safe integer. Use `bigIntToBytes` instead.',\n );\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Convert a `string` to a UTF-8 encoded `Uint8Array`.\n *\n * @param value - The string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function stringToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return new TextEncoder().encode(value);\n}\n\n/**\n * Convert a base64 encoded string to a `Uint8Array`.\n *\n * @param value - The base64 encoded string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function base64ToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return base64.decode(value);\n}\n\n/**\n * Convert a byte-like value to a `Uint8Array`. The value can be a `Uint8Array`,\n * a `bigint`, a `number`, or a `string`.\n *\n * This will attempt to guess the type of the value based on its type and\n * contents. For more control over the conversion, use the more specific\n * conversion functions, such as {@link hexToBytes} or {@link stringToBytes}.\n *\n * If the value is a `string`, and it is prefixed with `0x`, it will be\n * interpreted as a hexadecimal string. Otherwise, it will be interpreted as a\n * UTF-8 string. To convert a hexadecimal string to bytes without interpreting\n * it as a UTF-8 string, use {@link hexToBytes} instead.\n *\n * If the value is a `bigint`, it is assumed to be unsigned. To convert a signed\n * `bigint` to bytes, use {@link signedBigIntToBytes} instead.\n *\n * If the value is a `Uint8Array`, it will be returned as-is.\n *\n * @param value - The value to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function valueToBytes(value: Bytes): Uint8Array {\n if (typeof value === 'bigint') {\n return bigIntToBytes(value);\n }\n\n if (typeof value === 'number') {\n return numberToBytes(value);\n }\n\n if (typeof value === 'string') {\n if (value.startsWith('0x')) {\n return hexToBytes(value);\n }\n\n return stringToBytes(value);\n }\n\n if (isBytes(value)) {\n return value;\n }\n\n throw new TypeError(`Unsupported value type: \"${typeof value}\".`);\n}\n\n/**\n * Concatenate multiple byte-like values into a single `Uint8Array`. The values\n * can be `Uint8Array`, `bigint`, `number`, or `string`. This uses\n * {@link valueToBytes} under the hood to convert each value to bytes. Refer to\n * the documentation of that function for more information.\n *\n * @param values - The values to concatenate.\n * @returns The concatenated bytes as `Uint8Array`.\n */\nexport function concatBytes(values: Bytes[]): Uint8Array {\n const normalizedValues = new Array(values.length);\n let byteLength = 0;\n\n for (let i = 0; i < values.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = valueToBytes(values[i]!);\n\n normalizedValues[i] = value;\n byteLength += value.length;\n }\n\n const bytes = new Uint8Array(byteLength);\n for (let i = 0, offset = 0; i < normalizedValues.length; i++) {\n // While we could simply spread the values into an array and use\n // `Uint8Array.from`, that is a lot slower than using `Uint8Array.set`.\n bytes.set(normalizedValues[i], offset);\n offset += normalizedValues[i].length;\n }\n\n return bytes;\n}\n\n/**\n * Create a {@link DataView} from a {@link Uint8Array}. This is a convenience\n * function that avoids having to create a {@link DataView} manually, which\n * requires passing the `byteOffset` and `byteLength` parameters every time.\n *\n * Not passing the `byteOffset` and `byteLength` parameters can result in\n * unexpected behavior when the {@link Uint8Array} is a view of a larger\n * {@link ArrayBuffer}, e.g., when using {@link Uint8Array.subarray}.\n *\n * This function also supports Node.js {@link Buffer}s.\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([1, 2, 3]);\n *\n * // This is equivalent to:\n * // const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n * const dataView = createDataView(bytes);\n * ```\n * @param bytes - The bytes to create the {@link DataView} from.\n * @returns The {@link DataView}.\n */\nexport function createDataView(bytes: Uint8Array): DataView {\n // To maintain compatibility with Node.js, we need to check if the bytes are\n // a Buffer. If so, we need to slice the buffer to get the underlying\n // ArrayBuffer.\n // eslint-disable-next-line no-restricted-globals\n if (typeof Buffer !== 'undefined' && bytes instanceof Buffer) {\n const buffer = bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n );\n\n return new DataView(buffer);\n }\n\n return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bytes.cjs","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":";;;AAAA,sCAAqC;AAErC,yCAAkC;AAElC,mCAA2D;AAE3D,2BAA2B;AAC3B,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAExC,2BAA2B;AAC3B,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAIhC;;;;;;;;;;;;;GAaG;AACH,SAAS,8BAA8B;IACrC,6EAA6E;IAC7E,6EAA6E;IAC7E,6EAA6E;IAC7E,eAAe;IACf,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,OAAO,GAAG,EAAE;QACV,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;YAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;gBAC5B,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;aACnD;SACF;QAED,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,uBAAuB,GAAG,8BAA8B,EAAE,CAAC;AAEjE;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,KAAc;IACpC,OAAO,KAAK,YAAY,UAAU,CAAC;AACrC,CAAC;AAFD,0BAEC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,IAAA,eAAM,EAAC,OAAO,CAAC,KAAK,CAAC,EAAE,6BAA6B,CAAC,CAAC;AACxD,CAAC;AAFD,sCAEC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,KAAiB;IAC1C,aAAa,CAAC,KAAK,CAAC,CAAC;IAErB,IAAI,KAAK,CAAC,M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AC,CAAC;AACxE,CAAC;AAfD,wCAeC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,mBAAmB,CAAC,CAAa,EAAE,CAAa;IAC9D,sCAAsC;IACtC,IAAI,IAAI,GAAG,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC;IACvC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC;IAEjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;QAC5B,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACxB,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACxB,sCAAsC;QACtC,IAAI,IAAI,KAAK,GAAG,KAAK,CAAC;KACvB;IAED,OAAO,IAAI,KAAK,CAAC,CAAC;AACpB,CAAC;AAbD,kDAaC","sourcesContent":["import { base64 } from '@scure/base';\n\nimport { assert } from './assert';\nimport type { Hex } from './hex';\nimport { add0x, assertIsHexString, remove0x } from './hex';\n\n// '0'.charCodeAt(0) === 48\nconst HEX_MINIMUM_NUMBER_CHARACTER = 48;\n\n// '9'.charCodeAt(0) === 57\nconst HEX_MAXIMUM_NUMBER_CHARACTER = 58;\nconst HEX_CHARACTER_OFFSET = 87;\n\nexport type Bytes = bigint | number | string | Uint8Array;\n\n/**\n * Memoized function that returns an array to be used as a lookup table for\n * converting bytes to hexadecimal values.\n *\n * The array is created lazily and then cached for future use. The benefit of\n * this approach is that the performance of converting bytes to hex is much\n * better than if we were to call `toString(16)` on each byte.\n *\n * The downside is that the array is created once and then never garbage\n * collected. This is not a problem in practice because the array is only 256\n * elements long.\n *\n * @returns A function that returns the lookup table.\n */\nfunction getPrecomputedHexValuesBuilder(): () => string[] {\n // To avoid issues with tree shaking, we need to use a function to return the\n // array. This is because the array is only used in the `bytesToHex` function\n // and if we were to use a global variable, the array might be removed by the\n // tree shaker.\n const lookupTable: string[] = [];\n\n return () => {\n if (lookupTable.length === 0) {\n for (let i = 0; i < 256; i++) {\n lookupTable.push(i.toString(16).padStart(2, '0'));\n }\n }\n\n return lookupTable;\n };\n}\n\n/**\n * Function implementation of the {@link getPrecomputedHexValuesBuilder}\n * function.\n */\nconst getPrecomputedHexValues = getPrecomputedHexValuesBuilder();\n\n/**\n * Check if a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @returns Whether the value is a `Uint8Array`.\n */\nexport function isBytes(value: unknown): value is Uint8Array {\n return value instanceof Uint8Array;\n}\n\n/**\n * Assert that a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @throws If the value is not a `Uint8Array`.\n */\nexport function assertIsBytes(value: unknown): asserts value is Uint8Array {\n assert(isBytes(value), 'Value must be a Uint8Array.');\n}\n\n/**\n * Convert a `Uint8Array` to a hexadecimal string.\n *\n * @param bytes - The bytes to convert to a hexadecimal string.\n * @returns The hexadecimal string.\n */\nexport function bytesToHex(bytes: Uint8Array): Hex {\n assertIsBytes(bytes);\n\n if (bytes.length === 0) {\n return '0x';\n }\n\n const lookupTable = getPrecomputedHexValues();\n const hexadecimal = new Array(bytes.length);\n\n for (let i = 0; i < bytes.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n hexadecimal[i] = lookupTable[bytes[i]!];\n }\n\n return add0x(hexadecimal.join(''));\n}\n\n/**\n * Convert a `Uint8Array` to a `bigint`.\n *\n * To convert a `Uint8Array` to a `number` instead, use {@link bytesToNumber}.\n * To convert a two's complement encoded `Uint8Array` to a `bigint`, use\n * {@link bytesToSignedBigInt}.\n *\n * @param bytes - The bytes to convert to a `bigint`.\n * @returns The `bigint`.\n */\nexport function bytesToBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n const hexadecimal = bytesToHex(bytes);\n return BigInt(hexadecimal);\n}\n\n/**\n * Convert a `Uint8Array` to a signed `bigint`. This assumes that the bytes are\n * encoded in two's complement.\n *\n * To convert a `Uint8Array` to an unsigned `bigint` instead, use\n * {@link bytesToBigInt}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param bytes - The bytes to convert to a signed `bigint`.\n * @returns The signed `bigint`.\n */\nexport function bytesToSignedBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n let value = BigInt(0);\n for (const byte of bytes) {\n // eslint-disable-next-line no-bitwise\n value = (value << BigInt(8)) + BigInt(byte);\n }\n\n return BigInt.asIntN(bytes.length * 8, value);\n}\n\n/**\n * Convert a `Uint8Array` to a `number`.\n *\n * To convert a `Uint8Array` to a `bigint` instead, use {@link bytesToBigInt}.\n *\n * @param bytes - The bytes to convert to a number.\n * @returns The number.\n * @throws If the resulting number is not a safe integer.\n */\nexport function bytesToNumber(bytes: Uint8Array): number {\n assertIsBytes(bytes);\n\n const bigint = bytesToBigInt(bytes);\n\n assert(\n bigint <= BigInt(Number.MAX_SAFE_INTEGER),\n 'Number is not a safe integer. Use `bytesToBigInt` instead.',\n );\n\n return Number(bigint);\n}\n\n/**\n * Convert a UTF-8 encoded `Uint8Array` to a `string`.\n *\n * @param bytes - The bytes to convert to a string.\n * @returns The string.\n */\nexport function bytesToString(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return new TextDecoder().decode(bytes);\n}\n\n/**\n * Convert a `Uint8Array` to a base64 encoded string.\n *\n * @param bytes - The bytes to convert to a base64 encoded string.\n * @returns The base64 encoded string.\n */\nexport function bytesToBase64(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return base64.encode(bytes);\n}\n\n/**\n * Convert a hexadecimal string to a `Uint8Array`. The string can optionally be\n * prefixed with `0x`. It accepts even and odd length strings.\n *\n * If the value is \"0x\", an empty `Uint8Array` is returned.\n *\n * @param value - The hexadecimal string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function hexToBytes(value: string): Uint8Array {\n // \"0x\" is often used as empty byte array.\n if (value?.toLowerCase?.() === '0x') {\n return new Uint8Array();\n }\n\n assertIsHexString(value);\n\n // Remove the `0x` prefix if it exists, and pad the string to have an even\n // number of characters.\n const strippedValue = remove0x(value).toLowerCase();\n const normalizedValue =\n strippedValue.length % 2 === 0 ? strippedValue : `0${strippedValue}`;\n const bytes = new Uint8Array(normalizedValue.length / 2);\n\n for (let i = 0; i < bytes.length; i++) {\n // While this is not the prettiest way to convert a hexadecimal string to a\n // `Uint8Array`, it is a lot faster than using `parseInt` to convert each\n // character.\n const c1 = normalizedValue.charCodeAt(i * 2);\n const c2 = normalizedValue.charCodeAt(i * 2 + 1);\n const n1 =\n c1 -\n (c1 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n const n2 =\n c2 -\n (c2 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n\n bytes[i] = n1 * 16 + n2;\n }\n\n return bytes;\n}\n\n/**\n * Convert a `bigint` to a `Uint8Array`.\n *\n * This assumes that the `bigint` is an unsigned integer. To convert a signed\n * `bigint` instead, use {@link signedBigIntToBytes}.\n *\n * @param value - The bigint to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function bigIntToBytes(value: bigint): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= BigInt(0), 'Value must be a non-negative bigint.');\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Check if a `bigint` fits in a certain number of bytes.\n *\n * @param value - The `bigint` to check.\n * @param bytes - The number of bytes.\n * @returns Whether the `bigint` fits in the number of bytes.\n */\nfunction bigIntFits(value: bigint, bytes: number): boolean {\n assert(bytes > 0);\n\n /* eslint-disable no-bitwise */\n const mask = value >> BigInt(31);\n return !(((~value & mask) + (value & ~mask)) >> BigInt(bytes * 8 + ~0));\n /* eslint-enable no-bitwise */\n}\n\n/**\n * Convert a signed `bigint` to a `Uint8Array`. This uses two's complement\n * encoding to represent negative numbers.\n *\n * To convert an unsigned `bigint` to a `Uint8Array` instead, use\n * {@link bigIntToBytes}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param value - The number to convert to bytes.\n * @param byteLength - The length of the resulting `Uint8Array`. If the number\n * is larger than the maximum value that can be represented by the given length,\n * an error is thrown.\n * @returns The bytes as `Uint8Array`.\n */\nexport function signedBigIntToBytes(\n value: bigint,\n byteLength: number,\n): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(typeof byteLength === 'number', 'Byte length must be a number.');\n assert(byteLength > 0, 'Byte length must be greater than 0.');\n assert(\n bigIntFits(value, byteLength),\n 'Byte length is too small to represent the given value.',\n );\n\n // ESLint doesn't like mutating function parameters, so to avoid having to\n // disable the rule, we create a new variable.\n let numberValue = value;\n const bytes = new Uint8Array(byteLength);\n\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Number(BigInt.asUintN(8, numberValue));\n // eslint-disable-next-line no-bitwise\n numberValue >>= BigInt(8);\n }\n\n return bytes.reverse();\n}\n\n/**\n * Convert a `number` to a `Uint8Array`.\n *\n * @param value - The number to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n * @throws If the number is not a safe integer.\n */\nexport function numberToBytes(value: number): Uint8Array {\n assert(typeof value === 'number', 'Value must be a number.');\n assert(value >= 0, 'Value must be a non-negative number.');\n assert(\n Number.isSafeInteger(value),\n 'Value is not a safe integer. Use `bigIntToBytes` instead.',\n );\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Convert a `string` to a UTF-8 encoded `Uint8Array`.\n *\n * @param value - The string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function stringToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return new TextEncoder().encode(value);\n}\n\n/**\n * Convert a base64 encoded string to a `Uint8Array`.\n *\n * @param value - The base64 encoded string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function base64ToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return base64.decode(value);\n}\n\n/**\n * Convert a byte-like value to a `Uint8Array`. The value can be a `Uint8Array`,\n * a `bigint`, a `number`, or a `string`.\n *\n * This will attempt to guess the type of the value based on its type and\n * contents. For more control over the conversion, use the more specific\n * conversion functions, such as {@link hexToBytes} or {@link stringToBytes}.\n *\n * If the value is a `string`, and it is prefixed with `0x`, it will be\n * interpreted as a hexadecimal string. Otherwise, it will be interpreted as a\n * UTF-8 string. To convert a hexadecimal string to bytes without interpreting\n * it as a UTF-8 string, use {@link hexToBytes} instead.\n *\n * If the value is a `bigint`, it is assumed to be unsigned. To convert a signed\n * `bigint` to bytes, use {@link signedBigIntToBytes} instead.\n *\n * If the value is a `Uint8Array`, it will be returned as-is.\n *\n * @param value - The value to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function valueToBytes(value: Bytes): Uint8Array {\n if (typeof value === 'bigint') {\n return bigIntToBytes(value);\n }\n\n if (typeof value === 'number') {\n return numberToBytes(value);\n }\n\n if (typeof value === 'string') {\n if (value.startsWith('0x')) {\n return hexToBytes(value);\n }\n\n return stringToBytes(value);\n }\n\n if (isBytes(value)) {\n return value;\n }\n\n throw new TypeError(`Unsupported value type: \"${typeof value}\".`);\n}\n\n/**\n * Concatenate multiple byte-like values into a single `Uint8Array`. The values\n * can be `Uint8Array`, `bigint`, `number`, or `string`. This uses\n * {@link valueToBytes} under the hood to convert each value to bytes. Refer to\n * the documentation of that function for more information.\n *\n * @param values - The values to concatenate.\n * @returns The concatenated bytes as `Uint8Array`.\n */\nexport function concatBytes(values: Bytes[]): Uint8Array {\n const normalizedValues = new Array(values.length);\n let byteLength = 0;\n\n for (let i = 0; i < values.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = valueToBytes(values[i]!);\n\n normalizedValues[i] = value;\n byteLength += value.length;\n }\n\n const bytes = new Uint8Array(byteLength);\n for (let i = 0, offset = 0; i < normalizedValues.length; i++) {\n // While we could simply spread the values into an array and use\n // `Uint8Array.from`, that is a lot slower than using `Uint8Array.set`.\n bytes.set(normalizedValues[i], offset);\n offset += normalizedValues[i].length;\n }\n\n return bytes;\n}\n\n/**\n * Create a {@link DataView} from a {@link Uint8Array}. This is a convenience\n * function that avoids having to create a {@link DataView} manually, which\n * requires passing the `byteOffset` and `byteLength` parameters every time.\n *\n * Not passing the `byteOffset` and `byteLength` parameters can result in\n * unexpected behavior when the {@link Uint8Array} is a view of a larger\n * {@link ArrayBuffer}, e.g., when using {@link Uint8Array.subarray}.\n *\n * This function also supports Node.js {@link Buffer}s.\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([1, 2, 3]);\n *\n * // This is equivalent to:\n * // const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n * const dataView = createDataView(bytes);\n * ```\n * @param bytes - The bytes to create the {@link DataView} from.\n * @returns The {@link DataView}.\n */\nexport function createDataView(bytes: Uint8Array): DataView {\n // To maintain compatibility with Node.js, we need to check if the bytes are\n // a Buffer. If so, we need to slice the buffer to get the underlying\n // ArrayBuffer.\n // eslint-disable-next-line no-restricted-globals\n if (typeof Buffer !== 'undefined' && bytes instanceof Buffer) {\n const buffer = bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n );\n\n return new DataView(buffer);\n }\n\n return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n}\n\n/**\n * Compare two Uint8Arrays using a constant-time style loop to reduce timing\n * side-channels when comparing sensitive data (e.g., mnemonic bytes, keys,\n * authentication tags). Does not early-return on the first difference:\n * work done depends only on the input lengths, so byte content does not affect timing.\n *\n * When to use:\n * - Use for secret or security-sensitive byte comparisons to avoid content-based timing leaks.\n * - Prefer when inputs are fixed-length (or validated to equal length) at the API boundary.\n *\n * @param a - The first Uint8Array to compare.\n * @param b - The second Uint8Array to compare.\n * @returns Whether the Uint8Arrays are equal.\n */\nexport function areUint8ArraysEqual(a: Uint8Array, b: Uint8Array): boolean {\n // eslint-disable-next-line no-bitwise\n let diff = a.byteLength ^ b.byteLength;\n const len = Math.max(a.byteLength, b.byteLength);\n\n for (let i = 0; i < len; i++) {\n const aByte = a[i] ?? 0;\n const bByte = b[i] ?? 0;\n // eslint-disable-next-line no-bitwise\n diff |= aByte ^ bByte;\n }\n\n return diff === 0;\n}\n"]}
|
package/dist/bytes.d.cts
CHANGED
|
@@ -180,4 +180,19 @@ export declare function concatBytes(values: Bytes[]): Uint8Array;
|
|
|
180
180
|
* @returns The {@link DataView}.
|
|
181
181
|
*/
|
|
182
182
|
export declare function createDataView(bytes: Uint8Array): DataView;
|
|
183
|
+
/**
|
|
184
|
+
* Compare two Uint8Arrays using a constant-time style loop to reduce timing
|
|
185
|
+
* side-channels when comparing sensitive data (e.g., mnemonic bytes, keys,
|
|
186
|
+
* authentication tags). Does not early-return on the first difference:
|
|
187
|
+
* work done depends only on the input lengths, so byte content does not affect timing.
|
|
188
|
+
*
|
|
189
|
+
* When to use:
|
|
190
|
+
* - Use for secret or security-sensitive byte comparisons to avoid content-based timing leaks.
|
|
191
|
+
* - Prefer when inputs are fixed-length (or validated to equal length) at the API boundary.
|
|
192
|
+
*
|
|
193
|
+
* @param a - The first Uint8Array to compare.
|
|
194
|
+
* @param b - The second Uint8Array to compare.
|
|
195
|
+
* @returns Whether the Uint8Arrays are equal.
|
|
196
|
+
*/
|
|
197
|
+
export declare function areUint8ArraysEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
183
198
|
//# sourceMappingURL=bytes.d.cts.map
|
package/dist/bytes.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes.d.cts","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,kBAAc;AAUjC,MAAM,MAAM,KAAK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,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAoCpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAMvD;AAkBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GACjB,UAAU,CAqBZ;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAUvD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAIvD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAIvD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,CAsBrD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,UAAU,CAqBvD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAe1D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAazE"}
|
package/dist/bytes.d.mts
CHANGED
|
@@ -180,4 +180,19 @@ export declare function concatBytes(values: Bytes[]): Uint8Array;
|
|
|
180
180
|
* @returns The {@link DataView}.
|
|
181
181
|
*/
|
|
182
182
|
export declare function createDataView(bytes: Uint8Array): DataView;
|
|
183
|
+
/**
|
|
184
|
+
* Compare two Uint8Arrays using a constant-time style loop to reduce timing
|
|
185
|
+
* side-channels when comparing sensitive data (e.g., mnemonic bytes, keys,
|
|
186
|
+
* authentication tags). Does not early-return on the first difference:
|
|
187
|
+
* work done depends only on the input lengths, so byte content does not affect timing.
|
|
188
|
+
*
|
|
189
|
+
* When to use:
|
|
190
|
+
* - Use for secret or security-sensitive byte comparisons to avoid content-based timing leaks.
|
|
191
|
+
* - Prefer when inputs are fixed-length (or validated to equal length) at the API boundary.
|
|
192
|
+
*
|
|
193
|
+
* @param a - The first Uint8Array to compare.
|
|
194
|
+
* @param b - The second Uint8Array to compare.
|
|
195
|
+
* @returns Whether the Uint8Arrays are equal.
|
|
196
|
+
*/
|
|
197
|
+
export declare function areUint8ArraysEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
183
198
|
//# sourceMappingURL=bytes.d.mts.map
|
package/dist/bytes.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes.d.mts","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,kBAAc;AAUjC,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;AAwC1D;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAE3D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,UAAU,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,GAAG,CAgBjD;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAKvD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAU7D;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAWvD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIv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U,CAqBvD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAe1D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAazE"}
|
package/dist/bytes.mjs
CHANGED
|
@@ -377,4 +377,30 @@ export function createDataView(bytes) {
|
|
|
377
377
|
}
|
|
378
378
|
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
379
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* Compare two Uint8Arrays using a constant-time style loop to reduce timing
|
|
382
|
+
* side-channels when comparing sensitive data (e.g., mnemonic bytes, keys,
|
|
383
|
+
* authentication tags). Does not early-return on the first difference:
|
|
384
|
+
* work done depends only on the input lengths, so byte content does not affect timing.
|
|
385
|
+
*
|
|
386
|
+
* When to use:
|
|
387
|
+
* - Use for secret or security-sensitive byte comparisons to avoid content-based timing leaks.
|
|
388
|
+
* - Prefer when inputs are fixed-length (or validated to equal length) at the API boundary.
|
|
389
|
+
*
|
|
390
|
+
* @param a - The first Uint8Array to compare.
|
|
391
|
+
* @param b - The second Uint8Array to compare.
|
|
392
|
+
* @returns Whether the Uint8Arrays are equal.
|
|
393
|
+
*/
|
|
394
|
+
export function areUint8ArraysEqual(a, b) {
|
|
395
|
+
// eslint-disable-next-line no-bitwise
|
|
396
|
+
let diff = a.byteLength ^ b.byteLength;
|
|
397
|
+
const len = Math.max(a.byteLength, b.byteLength);
|
|
398
|
+
for (let i = 0; i < len; i++) {
|
|
399
|
+
const aByte = a[i] ?? 0;
|
|
400
|
+
const bByte = b[i] ?? 0;
|
|
401
|
+
// eslint-disable-next-line no-bitwise
|
|
402
|
+
diff |= aByte ^ bByte;
|
|
403
|
+
}
|
|
404
|
+
return diff === 0;
|
|
405
|
+
}
|
|
380
406
|
//# sourceMappingURL=bytes.mjs.map
|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AE,EAAE;QACtC,oEAAoE;QACpE,MAAM,KAAK,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC,CAAC;QAEvC,gBAAgB,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;QAC5B,UAAU,IAAI,KAAK,CAAC,MAAM,CAAC;KAC5B;IAED,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;IACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC5D,gEAAgE;QAChE,uEAAuE;QACvE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACvC,MAAM,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;KACtC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,cAAc,CAAC,KAAiB;IAC9C,4EAA4E;IAC5E,qEAAqE;IACrE,eAAe;IACf,iDAAiD;IACjD,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,KAAK,YAAY,MAAM,EAAE;QAC5D,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAC/B,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CACpC,CAAC;QAEF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;KAC7B;IAED,OAAO,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;AACxE,CAAC","sourcesContent":["import { base64 } from '@scure/base';\n\nimport { assert } from './assert';\nimport type { Hex } from './hex';\nimport { add0x, assertIsHexString, remove0x } from './hex';\n\n// '0'.charCodeAt(0) === 48\nconst HEX_MINIMUM_NUMBER_CHARACTER = 48;\n\n// '9'.charCodeAt(0) === 57\nconst HEX_MAXIMUM_NUMBER_CHARACTER = 58;\nconst HEX_CHARACTER_OFFSET = 87;\n\nexport type Bytes = bigint | number | string | Uint8Array;\n\n/**\n * Memoized function that returns an array to be used as a lookup table for\n * converting bytes to hexadecimal values.\n *\n * The array is created lazily and then cached for future use. The benefit of\n * this approach is that the performance of converting bytes to hex is much\n * better than if we were to call `toString(16)` on each byte.\n *\n * The downside is that the array is created once and then never garbage\n * collected. This is not a problem in practice because the array is only 256\n * elements long.\n *\n * @returns A function that returns the lookup table.\n */\nfunction getPrecomputedHexValuesBuilder(): () => string[] {\n // To avoid issues with tree shaking, we need to use a function to return the\n // array. This is because the array is only used in the `bytesToHex` function\n // and if we were to use a global variable, the array might be removed by the\n // tree shaker.\n const lookupTable: string[] = [];\n\n return () => {\n if (lookupTable.length === 0) {\n for (let i = 0; i < 256; i++) {\n lookupTable.push(i.toString(16).padStart(2, '0'));\n }\n }\n\n return lookupTable;\n };\n}\n\n/**\n * Function implementation of the {@link getPrecomputedHexValuesBuilder}\n * function.\n */\nconst getPrecomputedHexValues = getPrecomputedHexValuesBuilder();\n\n/**\n * Check if a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @returns Whether the value is a `Uint8Array`.\n */\nexport function isBytes(value: unknown): value is Uint8Array {\n return value instanceof Uint8Array;\n}\n\n/**\n * Assert that a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @throws If the value is not a `Uint8Array`.\n */\nexport function assertIsBytes(value: unknown): asserts value is Uint8Array {\n assert(isBytes(value), 'Value must be a Uint8Array.');\n}\n\n/**\n * Convert a `Uint8Array` to a hexadecimal string.\n *\n * @param bytes - The bytes to convert to a hexadecimal string.\n * @returns The hexadecimal string.\n */\nexport function bytesToHex(bytes: Uint8Array): Hex {\n assertIsBytes(bytes);\n\n if (bytes.length === 0) {\n return '0x';\n }\n\n const lookupTable = getPrecomputedHexValues();\n const hexadecimal = new Array(bytes.length);\n\n for (let i = 0; i < bytes.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n hexadecimal[i] = lookupTable[bytes[i]!];\n }\n\n return add0x(hexadecimal.join(''));\n}\n\n/**\n * Convert a `Uint8Array` to a `bigint`.\n *\n * To convert a `Uint8Array` to a `number` instead, use {@link bytesToNumber}.\n * To convert a two's complement encoded `Uint8Array` to a `bigint`, use\n * {@link bytesToSignedBigInt}.\n *\n * @param bytes - The bytes to convert to a `bigint`.\n * @returns The `bigint`.\n */\nexport function bytesToBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n const hexadecimal = bytesToHex(bytes);\n return BigInt(hexadecimal);\n}\n\n/**\n * Convert a `Uint8Array` to a signed `bigint`. This assumes that the bytes are\n * encoded in two's complement.\n *\n * To convert a `Uint8Array` to an unsigned `bigint` instead, use\n * {@link bytesToBigInt}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param bytes - The bytes to convert to a signed `bigint`.\n * @returns The signed `bigint`.\n */\nexport function bytesToSignedBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n let value = BigInt(0);\n for (const byte of bytes) {\n // eslint-disable-next-line no-bitwise\n value = (value << BigInt(8)) + BigInt(byte);\n }\n\n return BigInt.asIntN(bytes.length * 8, value);\n}\n\n/**\n * Convert a `Uint8Array` to a `number`.\n *\n * To convert a `Uint8Array` to a `bigint` instead, use {@link bytesToBigInt}.\n *\n * @param bytes - The bytes to convert to a number.\n * @returns The number.\n * @throws If the resulting number is not a safe integer.\n */\nexport function bytesToNumber(bytes: Uint8Array): number {\n assertIsBytes(bytes);\n\n const bigint = bytesToBigInt(bytes);\n\n assert(\n bigint <= BigInt(Number.MAX_SAFE_INTEGER),\n 'Number is not a safe integer. Use `bytesToBigInt` instead.',\n );\n\n return Number(bigint);\n}\n\n/**\n * Convert a UTF-8 encoded `Uint8Array` to a `string`.\n *\n * @param bytes - The bytes to convert to a string.\n * @returns The string.\n */\nexport function bytesToString(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return new TextDecoder().decode(bytes);\n}\n\n/**\n * Convert a `Uint8Array` to a base64 encoded string.\n *\n * @param bytes - The bytes to convert to a base64 encoded string.\n * @returns The base64 encoded string.\n */\nexport function bytesToBase64(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return base64.encode(bytes);\n}\n\n/**\n * Convert a hexadecimal string to a `Uint8Array`. The string can optionally be\n * prefixed with `0x`. It accepts even and odd length strings.\n *\n * If the value is \"0x\", an empty `Uint8Array` is returned.\n *\n * @param value - The hexadecimal string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function hexToBytes(value: string): Uint8Array {\n // \"0x\" is often used as empty byte array.\n if (value?.toLowerCase?.() === '0x') {\n return new Uint8Array();\n }\n\n assertIsHexString(value);\n\n // Remove the `0x` prefix if it exists, and pad the string to have an even\n // number of characters.\n const strippedValue = remove0x(value).toLowerCase();\n const normalizedValue =\n strippedValue.length % 2 === 0 ? strippedValue : `0${strippedValue}`;\n const bytes = new Uint8Array(normalizedValue.length / 2);\n\n for (let i = 0; i < bytes.length; i++) {\n // While this is not the prettiest way to convert a hexadecimal string to a\n // `Uint8Array`, it is a lot faster than using `parseInt` to convert each\n // character.\n const c1 = normalizedValue.charCodeAt(i * 2);\n const c2 = normalizedValue.charCodeAt(i * 2 + 1);\n const n1 =\n c1 -\n (c1 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n const n2 =\n c2 -\n (c2 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n\n bytes[i] = n1 * 16 + n2;\n }\n\n return bytes;\n}\n\n/**\n * Convert a `bigint` to a `Uint8Array`.\n *\n * This assumes that the `bigint` is an unsigned integer. To convert a signed\n * `bigint` instead, use {@link signedBigIntToBytes}.\n *\n * @param value - The bigint to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function bigIntToBytes(value: bigint): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= BigInt(0), 'Value must be a non-negative bigint.');\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Check if a `bigint` fits in a certain number of bytes.\n *\n * @param value - The `bigint` to check.\n * @param bytes - The number of bytes.\n * @returns Whether the `bigint` fits in the number of bytes.\n */\nfunction bigIntFits(value: bigint, bytes: number): boolean {\n assert(bytes > 0);\n\n /* eslint-disable no-bitwise */\n const mask = value >> BigInt(31);\n return !(((~value & mask) + (value & ~mask)) >> BigInt(bytes * 8 + ~0));\n /* eslint-enable no-bitwise */\n}\n\n/**\n * Convert a signed `bigint` to a `Uint8Array`. This uses two's complement\n * encoding to represent negative numbers.\n *\n * To convert an unsigned `bigint` to a `Uint8Array` instead, use\n * {@link bigIntToBytes}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param value - The number to convert to bytes.\n * @param byteLength - The length of the resulting `Uint8Array`. If the number\n * is larger than the maximum value that can be represented by the given length,\n * an error is thrown.\n * @returns The bytes as `Uint8Array`.\n */\nexport function signedBigIntToBytes(\n value: bigint,\n byteLength: number,\n): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(typeof byteLength === 'number', 'Byte length must be a number.');\n assert(byteLength > 0, 'Byte length must be greater than 0.');\n assert(\n bigIntFits(value, byteLength),\n 'Byte length is too small to represent the given value.',\n );\n\n // ESLint doesn't like mutating function parameters, so to avoid having to\n // disable the rule, we create a new variable.\n let numberValue = value;\n const bytes = new Uint8Array(byteLength);\n\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Number(BigInt.asUintN(8, numberValue));\n // eslint-disable-next-line no-bitwise\n numberValue >>= BigInt(8);\n }\n\n return bytes.reverse();\n}\n\n/**\n * Convert a `number` to a `Uint8Array`.\n *\n * @param value - The number to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n * @throws If the number is not a safe integer.\n */\nexport function numberToBytes(value: number): Uint8Array {\n assert(typeof value === 'number', 'Value must be a number.');\n assert(value >= 0, 'Value must be a non-negative number.');\n assert(\n Number.isSafeInteger(value),\n 'Value is not a safe integer. Use `bigIntToBytes` instead.',\n );\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Convert a `string` to a UTF-8 encoded `Uint8Array`.\n *\n * @param value - The string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function stringToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return new TextEncoder().encode(value);\n}\n\n/**\n * Convert a base64 encoded string to a `Uint8Array`.\n *\n * @param value - The base64 encoded string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function base64ToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return base64.decode(value);\n}\n\n/**\n * Convert a byte-like value to a `Uint8Array`. The value can be a `Uint8Array`,\n * a `bigint`, a `number`, or a `string`.\n *\n * This will attempt to guess the type of the value based on its type and\n * contents. For more control over the conversion, use the more specific\n * conversion functions, such as {@link hexToBytes} or {@link stringToBytes}.\n *\n * If the value is a `string`, and it is prefixed with `0x`, it will be\n * interpreted as a hexadecimal string. Otherwise, it will be interpreted as a\n * UTF-8 string. To convert a hexadecimal string to bytes without interpreting\n * it as a UTF-8 string, use {@link hexToBytes} instead.\n *\n * If the value is a `bigint`, it is assumed to be unsigned. To convert a signed\n * `bigint` to bytes, use {@link signedBigIntToBytes} instead.\n *\n * If the value is a `Uint8Array`, it will be returned as-is.\n *\n * @param value - The value to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function valueToBytes(value: Bytes): Uint8Array {\n if (typeof value === 'bigint') {\n return bigIntToBytes(value);\n }\n\n if (typeof value === 'number') {\n return numberToBytes(value);\n }\n\n if (typeof value === 'string') {\n if (value.startsWith('0x')) {\n return hexToBytes(value);\n }\n\n return stringToBytes(value);\n }\n\n if (isBytes(value)) {\n return value;\n }\n\n throw new TypeError(`Unsupported value type: \"${typeof value}\".`);\n}\n\n/**\n * Concatenate multiple byte-like values into a single `Uint8Array`. The values\n * can be `Uint8Array`, `bigint`, `number`, or `string`. This uses\n * {@link valueToBytes} under the hood to convert each value to bytes. Refer to\n * the documentation of that function for more information.\n *\n * @param values - The values to concatenate.\n * @returns The concatenated bytes as `Uint8Array`.\n */\nexport function concatBytes(values: Bytes[]): Uint8Array {\n const normalizedValues = new Array(values.length);\n let byteLength = 0;\n\n for (let i = 0; i < values.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = valueToBytes(values[i]!);\n\n normalizedValues[i] = value;\n byteLength += value.length;\n }\n\n const bytes = new Uint8Array(byteLength);\n for (let i = 0, offset = 0; i < normalizedValues.length; i++) {\n // While we could simply spread the values into an array and use\n // `Uint8Array.from`, that is a lot slower than using `Uint8Array.set`.\n bytes.set(normalizedValues[i], offset);\n offset += normalizedValues[i].length;\n }\n\n return bytes;\n}\n\n/**\n * Create a {@link DataView} from a {@link Uint8Array}. This is a convenience\n * function that avoids having to create a {@link DataView} manually, which\n * requires passing the `byteOffset` and `byteLength` parameters every time.\n *\n * Not passing the `byteOffset` and `byteLength` parameters can result in\n * unexpected behavior when the {@link Uint8Array} is a view of a larger\n * {@link ArrayBuffer}, e.g., when using {@link Uint8Array.subarray}.\n *\n * This function also supports Node.js {@link Buffer}s.\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([1, 2, 3]);\n *\n * // This is equivalent to:\n * // const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n * const dataView = createDataView(bytes);\n * ```\n * @param bytes - The bytes to create the {@link DataView} from.\n * @returns The {@link DataView}.\n */\nexport function createDataView(bytes: Uint8Array): DataView {\n // To maintain compatibility with Node.js, we need to check if the bytes are\n // a Buffer. If so, we need to slice the buffer to get the underlying\n // ArrayBuffer.\n // eslint-disable-next-line no-restricted-globals\n if (typeof Buffer !== 'undefined' && bytes instanceof Buffer) {\n const buffer = bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n );\n\n return new DataView(buffer);\n }\n\n return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bytes.mjs","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,oBAAoB;AAErC,OAAO,EAAE,MAAM,EAAE,qBAAiB;AAElC,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,kBAAc;AAE3D,2BAA2B;AAC3B,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAExC,2BAA2B;AAC3B,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAIhC;;;;;;;;;;;;;GAaG;AACH,SAAS,8BAA8B;IACrC,6EAA6E;IAC7E,6EAA6E;IAC7E,6EAA6E;IAC7E,eAAe;IACf,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,OAAO,GAAG,EAAE;QACV,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;YAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;gBAC5B,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;aACnD;SACF;QAED,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,uBAAuB,GAAG,8BAA8B,EAAE,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,OAAO,KAAK,YAAY,UAAU,CAAC;AACrC,CAAC;AAED;;;;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K,CAAC,UAAU,CAAC,CAAC;AACxE,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CAAC,CAAa,EAAE,CAAa;IAC9D,sCAAsC;IACtC,IAAI,IAAI,GAAG,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC;IACvC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC;IAEjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;QAC5B,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACxB,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACxB,sCAAsC;QACtC,IAAI,IAAI,KAAK,GAAG,KAAK,CAAC;KACvB;IAED,OAAO,IAAI,KAAK,CAAC,CAAC;AACpB,CAAC","sourcesContent":["import { base64 } from '@scure/base';\n\nimport { assert } from './assert';\nimport type { Hex } from './hex';\nimport { add0x, assertIsHexString, remove0x } from './hex';\n\n// '0'.charCodeAt(0) === 48\nconst HEX_MINIMUM_NUMBER_CHARACTER = 48;\n\n// '9'.charCodeAt(0) === 57\nconst HEX_MAXIMUM_NUMBER_CHARACTER = 58;\nconst HEX_CHARACTER_OFFSET = 87;\n\nexport type Bytes = bigint | number | string | Uint8Array;\n\n/**\n * Memoized function that returns an array to be used as a lookup table for\n * converting bytes to hexadecimal values.\n *\n * The array is created lazily and then cached for future use. The benefit of\n * this approach is that the performance of converting bytes to hex is much\n * better than if we were to call `toString(16)` on each byte.\n *\n * The downside is that the array is created once and then never garbage\n * collected. This is not a problem in practice because the array is only 256\n * elements long.\n *\n * @returns A function that returns the lookup table.\n */\nfunction getPrecomputedHexValuesBuilder(): () => string[] {\n // To avoid issues with tree shaking, we need to use a function to return the\n // array. This is because the array is only used in the `bytesToHex` function\n // and if we were to use a global variable, the array might be removed by the\n // tree shaker.\n const lookupTable: string[] = [];\n\n return () => {\n if (lookupTable.length === 0) {\n for (let i = 0; i < 256; i++) {\n lookupTable.push(i.toString(16).padStart(2, '0'));\n }\n }\n\n return lookupTable;\n };\n}\n\n/**\n * Function implementation of the {@link getPrecomputedHexValuesBuilder}\n * function.\n */\nconst getPrecomputedHexValues = getPrecomputedHexValuesBuilder();\n\n/**\n * Check if a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @returns Whether the value is a `Uint8Array`.\n */\nexport function isBytes(value: unknown): value is Uint8Array {\n return value instanceof Uint8Array;\n}\n\n/**\n * Assert that a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @throws If the value is not a `Uint8Array`.\n */\nexport function assertIsBytes(value: unknown): asserts value is Uint8Array {\n assert(isBytes(value), 'Value must be a Uint8Array.');\n}\n\n/**\n * Convert a `Uint8Array` to a hexadecimal string.\n *\n * @param bytes - The bytes to convert to a hexadecimal string.\n * @returns The hexadecimal string.\n */\nexport function bytesToHex(bytes: Uint8Array): Hex {\n assertIsBytes(bytes);\n\n if (bytes.length === 0) {\n return '0x';\n }\n\n const lookupTable = getPrecomputedHexValues();\n const hexadecimal = new Array(bytes.length);\n\n for (let i = 0; i < bytes.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n hexadecimal[i] = lookupTable[bytes[i]!];\n }\n\n return add0x(hexadecimal.join(''));\n}\n\n/**\n * Convert a `Uint8Array` to a `bigint`.\n *\n * To convert a `Uint8Array` to a `number` instead, use {@link bytesToNumber}.\n * To convert a two's complement encoded `Uint8Array` to a `bigint`, use\n * {@link bytesToSignedBigInt}.\n *\n * @param bytes - The bytes to convert to a `bigint`.\n * @returns The `bigint`.\n */\nexport function bytesToBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n const hexadecimal = bytesToHex(bytes);\n return BigInt(hexadecimal);\n}\n\n/**\n * Convert a `Uint8Array` to a signed `bigint`. This assumes that the bytes are\n * encoded in two's complement.\n *\n * To convert a `Uint8Array` to an unsigned `bigint` instead, use\n * {@link bytesToBigInt}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param bytes - The bytes to convert to a signed `bigint`.\n * @returns The signed `bigint`.\n */\nexport function bytesToSignedBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n let value = BigInt(0);\n for (const byte of bytes) {\n // eslint-disable-next-line no-bitwise\n value = (value << BigInt(8)) + BigInt(byte);\n }\n\n return BigInt.asIntN(bytes.length * 8, value);\n}\n\n/**\n * Convert a `Uint8Array` to a `number`.\n *\n * To convert a `Uint8Array` to a `bigint` instead, use {@link bytesToBigInt}.\n *\n * @param bytes - The bytes to convert to a number.\n * @returns The number.\n * @throws If the resulting number is not a safe integer.\n */\nexport function bytesToNumber(bytes: Uint8Array): number {\n assertIsBytes(bytes);\n\n const bigint = bytesToBigInt(bytes);\n\n assert(\n bigint <= BigInt(Number.MAX_SAFE_INTEGER),\n 'Number is not a safe integer. Use `bytesToBigInt` instead.',\n );\n\n return Number(bigint);\n}\n\n/**\n * Convert a UTF-8 encoded `Uint8Array` to a `string`.\n *\n * @param bytes - The bytes to convert to a string.\n * @returns The string.\n */\nexport function bytesToString(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return new TextDecoder().decode(bytes);\n}\n\n/**\n * Convert a `Uint8Array` to a base64 encoded string.\n *\n * @param bytes - The bytes to convert to a base64 encoded string.\n * @returns The base64 encoded string.\n */\nexport function bytesToBase64(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return base64.encode(bytes);\n}\n\n/**\n * Convert a hexadecimal string to a `Uint8Array`. The string can optionally be\n * prefixed with `0x`. It accepts even and odd length strings.\n *\n * If the value is \"0x\", an empty `Uint8Array` is returned.\n *\n * @param value - The hexadecimal string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function hexToBytes(value: string): Uint8Array {\n // \"0x\" is often used as empty byte array.\n if (value?.toLowerCase?.() === '0x') {\n return new Uint8Array();\n }\n\n assertIsHexString(value);\n\n // Remove the `0x` prefix if it exists, and pad the string to have an even\n // number of characters.\n const strippedValue = remove0x(value).toLowerCase();\n const normalizedValue =\n strippedValue.length % 2 === 0 ? strippedValue : `0${strippedValue}`;\n const bytes = new Uint8Array(normalizedValue.length / 2);\n\n for (let i = 0; i < bytes.length; i++) {\n // While this is not the prettiest way to convert a hexadecimal string to a\n // `Uint8Array`, it is a lot faster than using `parseInt` to convert each\n // character.\n const c1 = normalizedValue.charCodeAt(i * 2);\n const c2 = normalizedValue.charCodeAt(i * 2 + 1);\n const n1 =\n c1 -\n (c1 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n const n2 =\n c2 -\n (c2 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n\n bytes[i] = n1 * 16 + n2;\n }\n\n return bytes;\n}\n\n/**\n * Convert a `bigint` to a `Uint8Array`.\n *\n * This assumes that the `bigint` is an unsigned integer. To convert a signed\n * `bigint` instead, use {@link signedBigIntToBytes}.\n *\n * @param value - The bigint to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function bigIntToBytes(value: bigint): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= BigInt(0), 'Value must be a non-negative bigint.');\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Check if a `bigint` fits in a certain number of bytes.\n *\n * @param value - The `bigint` to check.\n * @param bytes - The number of bytes.\n * @returns Whether the `bigint` fits in the number of bytes.\n */\nfunction bigIntFits(value: bigint, bytes: number): boolean {\n assert(bytes > 0);\n\n /* eslint-disable no-bitwise */\n const mask = value >> BigInt(31);\n return !(((~value & mask) + (value & ~mask)) >> BigInt(bytes * 8 + ~0));\n /* eslint-enable no-bitwise */\n}\n\n/**\n * Convert a signed `bigint` to a `Uint8Array`. This uses two's complement\n * encoding to represent negative numbers.\n *\n * To convert an unsigned `bigint` to a `Uint8Array` instead, use\n * {@link bigIntToBytes}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param value - The number to convert to bytes.\n * @param byteLength - The length of the resulting `Uint8Array`. If the number\n * is larger than the maximum value that can be represented by the given length,\n * an error is thrown.\n * @returns The bytes as `Uint8Array`.\n */\nexport function signedBigIntToBytes(\n value: bigint,\n byteLength: number,\n): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(typeof byteLength === 'number', 'Byte length must be a number.');\n assert(byteLength > 0, 'Byte length must be greater than 0.');\n assert(\n bigIntFits(value, byteLength),\n 'Byte length is too small to represent the given value.',\n );\n\n // ESLint doesn't like mutating function parameters, so to avoid having to\n // disable the rule, we create a new variable.\n let numberValue = value;\n const bytes = new Uint8Array(byteLength);\n\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Number(BigInt.asUintN(8, numberValue));\n // eslint-disable-next-line no-bitwise\n numberValue >>= BigInt(8);\n }\n\n return bytes.reverse();\n}\n\n/**\n * Convert a `number` to a `Uint8Array`.\n *\n * @param value - The number to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n * @throws If the number is not a safe integer.\n */\nexport function numberToBytes(value: number): Uint8Array {\n assert(typeof value === 'number', 'Value must be a number.');\n assert(value >= 0, 'Value must be a non-negative number.');\n assert(\n Number.isSafeInteger(value),\n 'Value is not a safe integer. Use `bigIntToBytes` instead.',\n );\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Convert a `string` to a UTF-8 encoded `Uint8Array`.\n *\n * @param value - The string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function stringToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return new TextEncoder().encode(value);\n}\n\n/**\n * Convert a base64 encoded string to a `Uint8Array`.\n *\n * @param value - The base64 encoded string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function base64ToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return base64.decode(value);\n}\n\n/**\n * Convert a byte-like value to a `Uint8Array`. The value can be a `Uint8Array`,\n * a `bigint`, a `number`, or a `string`.\n *\n * This will attempt to guess the type of the value based on its type and\n * contents. For more control over the conversion, use the more specific\n * conversion functions, such as {@link hexToBytes} or {@link stringToBytes}.\n *\n * If the value is a `string`, and it is prefixed with `0x`, it will be\n * interpreted as a hexadecimal string. Otherwise, it will be interpreted as a\n * UTF-8 string. To convert a hexadecimal string to bytes without interpreting\n * it as a UTF-8 string, use {@link hexToBytes} instead.\n *\n * If the value is a `bigint`, it is assumed to be unsigned. To convert a signed\n * `bigint` to bytes, use {@link signedBigIntToBytes} instead.\n *\n * If the value is a `Uint8Array`, it will be returned as-is.\n *\n * @param value - The value to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function valueToBytes(value: Bytes): Uint8Array {\n if (typeof value === 'bigint') {\n return bigIntToBytes(value);\n }\n\n if (typeof value === 'number') {\n return numberToBytes(value);\n }\n\n if (typeof value === 'string') {\n if (value.startsWith('0x')) {\n return hexToBytes(value);\n }\n\n return stringToBytes(value);\n }\n\n if (isBytes(value)) {\n return value;\n }\n\n throw new TypeError(`Unsupported value type: \"${typeof value}\".`);\n}\n\n/**\n * Concatenate multiple byte-like values into a single `Uint8Array`. The values\n * can be `Uint8Array`, `bigint`, `number`, or `string`. This uses\n * {@link valueToBytes} under the hood to convert each value to bytes. Refer to\n * the documentation of that function for more information.\n *\n * @param values - The values to concatenate.\n * @returns The concatenated bytes as `Uint8Array`.\n */\nexport function concatBytes(values: Bytes[]): Uint8Array {\n const normalizedValues = new Array(values.length);\n let byteLength = 0;\n\n for (let i = 0; i < values.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = valueToBytes(values[i]!);\n\n normalizedValues[i] = value;\n byteLength += value.length;\n }\n\n const bytes = new Uint8Array(byteLength);\n for (let i = 0, offset = 0; i < normalizedValues.length; i++) {\n // While we could simply spread the values into an array and use\n // `Uint8Array.from`, that is a lot slower than using `Uint8Array.set`.\n bytes.set(normalizedValues[i], offset);\n offset += normalizedValues[i].length;\n }\n\n return bytes;\n}\n\n/**\n * Create a {@link DataView} from a {@link Uint8Array}. This is a convenience\n * function that avoids having to create a {@link DataView} manually, which\n * requires passing the `byteOffset` and `byteLength` parameters every time.\n *\n * Not passing the `byteOffset` and `byteLength` parameters can result in\n * unexpected behavior when the {@link Uint8Array} is a view of a larger\n * {@link ArrayBuffer}, e.g., when using {@link Uint8Array.subarray}.\n *\n * This function also supports Node.js {@link Buffer}s.\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([1, 2, 3]);\n *\n * // This is equivalent to:\n * // const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n * const dataView = createDataView(bytes);\n * ```\n * @param bytes - The bytes to create the {@link DataView} from.\n * @returns The {@link DataView}.\n */\nexport function createDataView(bytes: Uint8Array): DataView {\n // To maintain compatibility with Node.js, we need to check if the bytes are\n // a Buffer. If so, we need to slice the buffer to get the underlying\n // ArrayBuffer.\n // eslint-disable-next-line no-restricted-globals\n if (typeof Buffer !== 'undefined' && bytes instanceof Buffer) {\n const buffer = bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n );\n\n return new DataView(buffer);\n }\n\n return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n}\n\n/**\n * Compare two Uint8Arrays using a constant-time style loop to reduce timing\n * side-channels when comparing sensitive data (e.g., mnemonic bytes, keys,\n * authentication tags). Does not early-return on the first difference:\n * work done depends only on the input lengths, so byte content does not affect timing.\n *\n * When to use:\n * - Use for secret or security-sensitive byte comparisons to avoid content-based timing leaks.\n * - Prefer when inputs are fixed-length (or validated to equal length) at the API boundary.\n *\n * @param a - The first Uint8Array to compare.\n * @param b - The second Uint8Array to compare.\n * @returns Whether the Uint8Arrays are equal.\n */\nexport function areUint8ArraysEqual(a: Uint8Array, b: Uint8Array): boolean {\n // eslint-disable-next-line no-bitwise\n let diff = a.byteLength ^ b.byteLength;\n const len = Math.max(a.byteLength, b.byteLength);\n\n for (let i = 0; i < len; i++) {\n const aByte = a[i] ?? 0;\n const bByte = b[i] ?? 0;\n // eslint-disable-next-line no-bitwise\n diff |= aByte ^ bByte;\n }\n\n return diff === 0;\n}\n"]}
|
package/dist/caip-types.cjs
CHANGED
|
@@ -65,6 +65,8 @@ var KnownCaipNamespace;
|
|
|
65
65
|
KnownCaipNamespace["Bip122"] = "bip122";
|
|
66
66
|
/** Solana compatible chains */
|
|
67
67
|
KnownCaipNamespace["Solana"] = "solana";
|
|
68
|
+
/** Tron compatible chains */
|
|
69
|
+
KnownCaipNamespace["Tron"] = "tron";
|
|
68
70
|
/** EIP-155 compatible chains. */
|
|
69
71
|
KnownCaipNamespace["Eip155"] = "eip155";
|
|
70
72
|
KnownCaipNamespace["Wallet"] = "wallet";
|
package/dist/caip-types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip-types.cjs","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":";;;AACA,uDAA2C;AAE3C,mDAA8C;AAEjC,QAAA,mBAAmB,GAC9B,mEAAmE,CAAC;AAEzD,QAAA,oBAAoB,GAAG,mBAAmB,CAAC;AAE3C,QAAA,oBAAoB,GAAG,wBAAwB,CAAC;AAEhD,QAAA,qBAAqB,GAChC,wHAAwH,CAAC;AAE9G,QAAA,0BAA0B,GAAG,0BAA0B,CAAC;AAExD,QAAA,0BAA0B,GAAG,mBAAmB,CAAC;AAEjD,QAAA,0BAA0B,GAAG,0BAA0B,CAAC;AAExD,QAAA,mBAAmB,GAAG,yBAAyB,CAAC;AAEhD,QAAA,qBAAqB,GAChC,2JAA2J,CAAC;AAEjJ,QAAA,mBAAmB,GAC9B,6LAA6L,CAAC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F,CAAC;KACH;IAED,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE;QACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,kCAA0B,CAAC,QAAQ,EAAE,EAAE,CACjF,CAAC;KACH;IAED,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,cAAc,IAAI,cAAc,EAAE,CAAC;AACzE,CAAC;AA/BD,0CA+BC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,aAAa,CAC3B,SAAwB,EACxB,SAAwB,EACxB,cAAkC,EAClC,cAAkC,EAClC,OAAoB;IAEpB,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CACb,oCAAoC,4BAAoB,CAAC,QAAQ,EAAE,EAAE,CACtE,CAAC;KACH;IAED,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CACb,oCAAoC,4BAAoB,CAAC,QAAQ,EAAE,EAAE,CACtE,CAAC;KACH;IAED,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE;QACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,kCAA0B,CAAC,QAAQ,EAAE,EAAE,CACjF,CAAC;KACH;IAED,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE;QACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,kCAA0B,CAAC,QAAQ,EAAE,EAAE,CACjF,CAAC;KACH;IAED,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,kCAAkC,2BAAmB,CAAC,QAAQ,EAAE,EAAE,CACnE,CAAC;KACH;IAED,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,cAAc,IAAI,cAAc,IAAI,OAAO,EAAE,CAAC;AACpF,CAAC;AAtCD,sCAsCC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { is } from '@metamask/superstruct';\n\nimport { definePattern } from './superstruct';\n\nexport const CAIP_CHAIN_ID_REGEX =\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;\n\nexport const CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;\n\nexport const CAIP_ACCOUNT_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})):(?<accountAddress>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ACCOUNT_ADDRESS_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_ASSET_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_ASSET_REFERENCE_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_TOKEN_ID_REGEX = /^[-.%a-zA-Z0-9]{1,78}$/u;\n\nexport const CAIP_ASSET_TYPE_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ASSET_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;\n\nconst CAIP_ASSET_TYPE_OR_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})(\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78}))?$/u;\n\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const CaipChainIdStruct = definePattern<`${string}:${string}`>(\n 'CaipChainId',\n CAIP_CHAIN_ID_REGEX,\n);\nexport type CaipChainId = Infer<typeof CaipChainIdStruct>;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.\n */\nexport const CaipNamespaceStruct = definePattern(\n 'CaipNamespace',\n CAIP_NAMESPACE_REGEX,\n);\nexport type CaipNamespace = Infer<typeof CaipNamespaceStruct>;\n\n/**\n * A CAIP-2 reference, i.e., the second part of a CAIP chain ID.\n */\nexport const CaipReferenceStruct = definePattern(\n 'CaipReference',\n CAIP_REFERENCE_REGEX,\n);\nexport type CaipReference = Infer<typeof CaipReferenceStruct>;\n\n/**\n * A CAIP-10 account ID, i.e., a human-readable namespace, reference, and account address.\n */\nexport const CaipAccountIdStruct =\n definePattern<`${string}:${string}:${string}`>(\n 'CaipAccountId',\n CAIP_ACCOUNT_ID_REGEX,\n );\nexport type CaipAccountId = Infer<typeof CaipAccountIdStruct>;\n\n/**\n * A CAIP-10 account address, i.e., the third part of the CAIP account ID.\n */\nexport const CaipAccountAddressStruct = definePattern(\n 'CaipAccountAddress',\n CAIP_ACCOUNT_ADDRESS_REGEX,\n);\nexport type CaipAccountAddress = Infer<typeof CaipAccountAddressStruct>;\n\n/**\n * A CAIP-19 asset namespace, i.e., a namespace domain of an asset.\n */\nexport const CaipAssetNamespaceStruct = definePattern(\n 'CaipAssetNamespace',\n CAIP_ASSET_NAMESPACE_REGEX,\n);\nexport type CaipAssetNamespace = Infer<typeof CaipAssetNamespaceStruct>;\n\n/**\n * A CAIP-19 asset reference, i.e., an identifier for an asset within a given namespace.\n */\nexport const CaipAssetReferenceStruct = definePattern(\n 'CaipAssetReference',\n CAIP_ASSET_REFERENCE_REGEX,\n);\nexport type CaipAssetReference = Infer<typeof CaipAssetReferenceStruct>;\n\n/**\n * A CAIP-19 asset token ID, i.e., a unique identifier for an addressable asset of a given type\n */\nexport const CaipTokenIdStruct = definePattern(\n 'CaipTokenId',\n CAIP_TOKEN_ID_REGEX,\n);\nexport type CaipTokenId = Infer<typeof CaipTokenIdStruct>;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeStruct =\n definePattern<`${string}:${string}/${string}:${string}`>(\n 'CaipAssetType',\n CAIP_ASSET_TYPE_REGEX,\n );\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.\n */\nexport const CaipAssetIdStruct =\n definePattern<`${string}:${string}/${string}:${string}/${string}`>(\n 'CaipAssetId',\n CAIP_ASSET_ID_REGEX,\n );\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeOrIdStruct = definePattern<\n CaipAssetType | CaipAssetId\n>('CaipAssetTypeOrId', CAIP_ASSET_TYPE_OR_ID_REGEX);\nexport type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;\n\n/** Known CAIP namespaces. */\nexport enum KnownCaipNamespace {\n /** BIP-122 (Bitcoin) compatible chains. */\n Bip122 = 'bip122',\n /** Solana compatible chains */\n Solana = 'solana',\n /** EIP-155 compatible chains. */\n Eip155 = 'eip155',\n Wallet = 'wallet',\n}\n\n/**\n * A CAIP-2 chain ID that is guaranteed to have a known CAIP namespace\n * (@see {@link KnownCaipNamespace}).\n *\n * This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases\n * where the chain namespace must be one of the known standards.\n *\n * @template Namespace - The namespace of the CAIP-2 chain ID. Must be a known namespace specified in {@link KnownCaipNamespace}.\n */\nexport type KnownCaipNamespacedChainId<\n Namespace extends `${KnownCaipNamespace}` = `${KnownCaipNamespace}`,\n> = `${Namespace}:${string}`;\n\n/**\n * Check if the given value is a {@link CaipChainId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipChainId}.\n */\nexport function isCaipChainId(value: unknown): value is CaipChainId {\n return is(value, CaipChainIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipNamespace}.\n */\nexport function isCaipNamespace(value: unknown): value is CaipNamespace {\n return is(value, CaipNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipReference}.\n */\nexport function isCaipReference(value: unknown): value is CaipReference {\n return is(value, CaipReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAccountId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAccountId}.\n */\nexport function isCaipAccountId(value: unknown): value is CaipAccountId {\n return is(value, CaipAccountIdStruct);\n}\n\n/**\n * Check if a value is a {@link CaipAccountAddress}.\n *\n * @param value - The value to validate.\n * @returns True if the value is a valid {@link CaipAccountAddress}.\n */\nexport function isCaipAccountAddress(\n value: unknown,\n): value is CaipAccountAddress {\n return is(value, CaipAccountAddressStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetNamespace}.\n */\nexport function isCaipAssetNamespace(\n value: unknown,\n): value is CaipAssetNamespace {\n return is(value, CaipAssetNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetReference}.\n */\nexport function isCaipAssetReference(\n value: unknown,\n): value is CaipAssetReference {\n return is(value, CaipAssetReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipTokenId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipTokenId}.\n */\nexport function isCaipTokenId(value: unknown): value is CaipTokenId {\n return is(value, CaipTokenIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n\n/**\n * Parse a CAIP-2 chain ID to an object containing the namespace and reference.\n * This validates the CAIP-2 chain ID before parsing it.\n *\n * @param caipChainId - The CAIP-2 chain ID to validate and parse.\n * @returns The parsed CAIP-2 chain ID.\n */\nexport function parseCaipChainId(caipChainId: CaipChainId): {\n namespace: CaipNamespace;\n reference: CaipReference;\n} {\n const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP chain ID.');\n }\n\n return {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n };\n}\n\n/**\n * Parse an CAIP-10 account ID to an object containing the chain ID, parsed chain ID, and account address.\n * This validates the CAIP-10 account ID before parsing it.\n *\n * @param caipAccountId - The CAIP-10 account ID to validate and parse.\n * @returns The parsed CAIP-10 account ID.\n */\nexport function parseCaipAccountId(caipAccountId: CaipAccountId): {\n address: CaipAccountAddress;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ACCOUNT_ID_REGEX.exec(caipAccountId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP account ID.');\n }\n\n return {\n address: match.groups.accountAddress as CaipAccountAddress,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset type to an object containing the chain ID, parsed chain ID,\n * asset namespace, and asset reference\n *\n * This validates the CAIP-19 asset type before parsing it.\n *\n * @param caipAssetType - The CAIP-19 asset type to validate and parse.\n * @returns The parsed CAIP-19 asset type.\n */\nexport function parseCaipAssetType(caipAssetType: CaipAssetType): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_TYPE_REGEX.exec(caipAssetType);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset type.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset ID to an object containing the chain ID, parsed chain ID,\n * asset namespace, asset reference, and token ID.\n *\n * This validates the CAIP-19 asset ID before parsing it.\n *\n * @param caipAssetId - The CAIP-19 asset ID to validate and parse.\n * @returns The parsed CAIP-19 asset ID.\n */\nexport function parseCaipAssetId(caipAssetId: CaipAssetId): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n tokenId: CaipTokenId;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_ID_REGEX.exec(caipAssetId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset ID.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n tokenId: match.groups.tokenId as CaipTokenId,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Chain ID as defined per the CAIP-2\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md}.\n *\n * It defines a way to uniquely identify any blockchain in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identify of a blockchain within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs does not comply with the CAIP-2\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md#syntax}.\n * @returns A CAIP chain ID.\n */\nexport function toCaipChainId(\n namespace: CaipNamespace,\n reference: CaipReference,\n): CaipChainId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}`;\n}\n\n/**\n * Account ID as defined per the CAIP-10\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md}.\n *\n * It defines a way to uniquely identify any blockchain account in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param accountAddress - The address of the blockchain account.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-10\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md#syntax}.\n * @returns A CAIP account ID.\n */\nexport function toCaipAccountId(\n namespace: CaipNamespace,\n reference: CaipReference,\n accountAddress: CaipAccountAddress,\n): CaipAccountId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAccountAddress(accountAddress)) {\n throw new Error(\n `Invalid \"accountAddress\", must match: ${CAIP_ACCOUNT_ADDRESS_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}:${accountAddress}`;\n}\n\n/**\n * Asset Type as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset type.\n */\nexport function toCaipAssetType(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n): CaipAssetType {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}`;\n}\n\n/**\n * Asset ID as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @param tokenId - The unique identifier for an addressable asset of a given type.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset ID.\n */\nexport function toCaipAssetId(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n tokenId: CaipTokenId,\n): CaipAssetId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipTokenId(tokenId)) {\n throw new Error(\n `Invalid \"tokenId\", must match: ${CAIP_TOKEN_ID_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}/${tokenId}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"caip-types.cjs","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":";;;AACA,uDAA2C;AAE3C,mDAA8C;AAEjC,QAAA,mBAAmB,GAC9B,mEAAmE,CAAC;AAEzD,QAAA,oBAAoB,GAAG,mBAAmB,CAAC;AAE3C,QAAA,oBAAoB,GAAG,wBAAwB,CAAC;AAEhD,QAAA,qBAAqB,GAChC,wHAAwH,CAAC;AAE9G,QAAA,0BAA0B,GAAG,0BAA0B,CAAC;AAExD,QAAA,0BAA0B,GAAG,mBAAmB,CAAC;AAEjD,QAAA,0BAA0B,GAAG,0BAA0B,CAAC;AAExD,QAAA,mBAAmB,GAAG,yBAAyB,CAAC;AAEhD,QAAA,qBAAqB,GAChC,2JAA2J,CAAC;AAEjJ,Q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cesContent":["import type { Infer } from '@metamask/superstruct';\nimport { is } from '@metamask/superstruct';\n\nimport { definePattern } from './superstruct';\n\nexport const CAIP_CHAIN_ID_REGEX =\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;\n\nexport const CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;\n\nexport const CAIP_ACCOUNT_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})):(?<accountAddress>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ACCOUNT_ADDRESS_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_ASSET_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_ASSET_REFERENCE_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_TOKEN_ID_REGEX = /^[-.%a-zA-Z0-9]{1,78}$/u;\n\nexport const CAIP_ASSET_TYPE_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ASSET_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;\n\nconst CAIP_ASSET_TYPE_OR_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})(\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78}))?$/u;\n\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const CaipChainIdStruct = definePattern<`${string}:${string}`>(\n 'CaipChainId',\n CAIP_CHAIN_ID_REGEX,\n);\nexport type CaipChainId = Infer<typeof CaipChainIdStruct>;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.\n */\nexport const CaipNamespaceStruct = definePattern(\n 'CaipNamespace',\n CAIP_NAMESPACE_REGEX,\n);\nexport type CaipNamespace = Infer<typeof CaipNamespaceStruct>;\n\n/**\n * A CAIP-2 reference, i.e., the second part of a CAIP chain ID.\n */\nexport const CaipReferenceStruct = definePattern(\n 'CaipReference',\n CAIP_REFERENCE_REGEX,\n);\nexport type CaipReference = Infer<typeof CaipReferenceStruct>;\n\n/**\n * A CAIP-10 account ID, i.e., a human-readable namespace, reference, and account address.\n */\nexport const CaipAccountIdStruct =\n definePattern<`${string}:${string}:${string}`>(\n 'CaipAccountId',\n CAIP_ACCOUNT_ID_REGEX,\n );\nexport type CaipAccountId = Infer<typeof CaipAccountIdStruct>;\n\n/**\n * A CAIP-10 account address, i.e., the third part of the CAIP account ID.\n */\nexport const CaipAccountAddressStruct = definePattern(\n 'CaipAccountAddress',\n CAIP_ACCOUNT_ADDRESS_REGEX,\n);\nexport type CaipAccountAddress = Infer<typeof CaipAccountAddressStruct>;\n\n/**\n * A CAIP-19 asset namespace, i.e., a namespace domain of an asset.\n */\nexport const CaipAssetNamespaceStruct = definePattern(\n 'CaipAssetNamespace',\n CAIP_ASSET_NAMESPACE_REGEX,\n);\nexport type CaipAssetNamespace = Infer<typeof CaipAssetNamespaceStruct>;\n\n/**\n * A CAIP-19 asset reference, i.e., an identifier for an asset within a given namespace.\n */\nexport const CaipAssetReferenceStruct = definePattern(\n 'CaipAssetReference',\n CAIP_ASSET_REFERENCE_REGEX,\n);\nexport type CaipAssetReference = Infer<typeof CaipAssetReferenceStruct>;\n\n/**\n * A CAIP-19 asset token ID, i.e., a unique identifier for an addressable asset of a given type\n */\nexport const CaipTokenIdStruct = definePattern(\n 'CaipTokenId',\n CAIP_TOKEN_ID_REGEX,\n);\nexport type CaipTokenId = Infer<typeof CaipTokenIdStruct>;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeStruct =\n definePattern<`${string}:${string}/${string}:${string}`>(\n 'CaipAssetType',\n CAIP_ASSET_TYPE_REGEX,\n );\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.\n */\nexport const CaipAssetIdStruct =\n definePattern<`${string}:${string}/${string}:${string}/${string}`>(\n 'CaipAssetId',\n CAIP_ASSET_ID_REGEX,\n );\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeOrIdStruct = definePattern<\n CaipAssetType | CaipAssetId\n>('CaipAssetTypeOrId', CAIP_ASSET_TYPE_OR_ID_REGEX);\nexport type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;\n\n/** Known CAIP namespaces. */\nexport enum KnownCaipNamespace {\n /** BIP-122 (Bitcoin) compatible chains. */\n Bip122 = 'bip122',\n /** Solana compatible chains */\n Solana = 'solana',\n /** Tron compatible chains */\n Tron = 'tron',\n /** EIP-155 compatible chains. */\n Eip155 = 'eip155',\n Wallet = 'wallet',\n}\n\n/**\n * A CAIP-2 chain ID that is guaranteed to have a known CAIP namespace\n * (@see {@link KnownCaipNamespace}).\n *\n * This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases\n * where the chain namespace must be one of the known standards.\n *\n * @template Namespace - The namespace of the CAIP-2 chain ID. Must be a known namespace specified in {@link KnownCaipNamespace}.\n */\nexport type KnownCaipNamespacedChainId<\n Namespace extends `${KnownCaipNamespace}` = `${KnownCaipNamespace}`,\n> = `${Namespace}:${string}`;\n\n/**\n * Check if the given value is a {@link CaipChainId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipChainId}.\n */\nexport function isCaipChainId(value: unknown): value is CaipChainId {\n return is(value, CaipChainIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipNamespace}.\n */\nexport function isCaipNamespace(value: unknown): value is CaipNamespace {\n return is(value, CaipNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipReference}.\n */\nexport function isCaipReference(value: unknown): value is CaipReference {\n return is(value, CaipReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAccountId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAccountId}.\n */\nexport function isCaipAccountId(value: unknown): value is CaipAccountId {\n return is(value, CaipAccountIdStruct);\n}\n\n/**\n * Check if a value is a {@link CaipAccountAddress}.\n *\n * @param value - The value to validate.\n * @returns True if the value is a valid {@link CaipAccountAddress}.\n */\nexport function isCaipAccountAddress(\n value: unknown,\n): value is CaipAccountAddress {\n return is(value, CaipAccountAddressStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetNamespace}.\n */\nexport function isCaipAssetNamespace(\n value: unknown,\n): value is CaipAssetNamespace {\n return is(value, CaipAssetNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetReference}.\n */\nexport function isCaipAssetReference(\n value: unknown,\n): value is CaipAssetReference {\n return is(value, CaipAssetReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipTokenId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipTokenId}.\n */\nexport function isCaipTokenId(value: unknown): value is CaipTokenId {\n return is(value, CaipTokenIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n\n/**\n * Parse a CAIP-2 chain ID to an object containing the namespace and reference.\n * This validates the CAIP-2 chain ID before parsing it.\n *\n * @param caipChainId - The CAIP-2 chain ID to validate and parse.\n * @returns The parsed CAIP-2 chain ID.\n */\nexport function parseCaipChainId(caipChainId: CaipChainId): {\n namespace: CaipNamespace;\n reference: CaipReference;\n} {\n const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP chain ID.');\n }\n\n return {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n };\n}\n\n/**\n * Parse an CAIP-10 account ID to an object containing the chain ID, parsed chain ID, and account address.\n * This validates the CAIP-10 account ID before parsing it.\n *\n * @param caipAccountId - The CAIP-10 account ID to validate and parse.\n * @returns The parsed CAIP-10 account ID.\n */\nexport function parseCaipAccountId(caipAccountId: CaipAccountId): {\n address: CaipAccountAddress;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ACCOUNT_ID_REGEX.exec(caipAccountId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP account ID.');\n }\n\n return {\n address: match.groups.accountAddress as CaipAccountAddress,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset type to an object containing the chain ID, parsed chain ID,\n * asset namespace, and asset reference\n *\n * This validates the CAIP-19 asset type before parsing it.\n *\n * @param caipAssetType - The CAIP-19 asset type to validate and parse.\n * @returns The parsed CAIP-19 asset type.\n */\nexport function parseCaipAssetType(caipAssetType: CaipAssetType): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_TYPE_REGEX.exec(caipAssetType);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset type.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset ID to an object containing the chain ID, parsed chain ID,\n * asset namespace, asset reference, and token ID.\n *\n * This validates the CAIP-19 asset ID before parsing it.\n *\n * @param caipAssetId - The CAIP-19 asset ID to validate and parse.\n * @returns The parsed CAIP-19 asset ID.\n */\nexport function parseCaipAssetId(caipAssetId: CaipAssetId): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n tokenId: CaipTokenId;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_ID_REGEX.exec(caipAssetId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset ID.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n tokenId: match.groups.tokenId as CaipTokenId,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Chain ID as defined per the CAIP-2\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md}.\n *\n * It defines a way to uniquely identify any blockchain in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identify of a blockchain within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs does not comply with the CAIP-2\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md#syntax}.\n * @returns A CAIP chain ID.\n */\nexport function toCaipChainId(\n namespace: CaipNamespace,\n reference: CaipReference,\n): CaipChainId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}`;\n}\n\n/**\n * Account ID as defined per the CAIP-10\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md}.\n *\n * It defines a way to uniquely identify any blockchain account in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param accountAddress - The address of the blockchain account.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-10\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md#syntax}.\n * @returns A CAIP account ID.\n */\nexport function toCaipAccountId(\n namespace: CaipNamespace,\n reference: CaipReference,\n accountAddress: CaipAccountAddress,\n): CaipAccountId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAccountAddress(accountAddress)) {\n throw new Error(\n `Invalid \"accountAddress\", must match: ${CAIP_ACCOUNT_ADDRESS_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}:${accountAddress}`;\n}\n\n/**\n * Asset Type as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset type.\n */\nexport function toCaipAssetType(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n): CaipAssetType {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}`;\n}\n\n/**\n * Asset ID as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @param tokenId - The unique identifier for an addressable asset of a given type.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset ID.\n */\nexport function toCaipAssetId(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n tokenId: CaipTokenId,\n): CaipAssetId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipTokenId(tokenId)) {\n throw new Error(\n `Invalid \"tokenId\", must match: ${CAIP_TOKEN_ID_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}/${tokenId}`;\n}\n"]}
|
package/dist/caip-types.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip-types.d.cts","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAKnD,eAAO,MAAM,mBAAmB,QACqC,CAAC;AAEtE,eAAO,MAAM,oBAAoB,QAAsB,CAAC;AAExD,eAAO,MAAM,oBAAoB,QAA2B,CAAC;AAE7D,eAAO,MAAM,qBAAqB,QACwF,CAAC;AAE3H,eAAO,MAAM,0BAA0B,QAA6B,CAAC;AAErE,eAAO,MAAM,0BAA0B,Q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mjs
CHANGED
|
@@ -62,6 +62,8 @@ export var KnownCaipNamespace;
|
|
|
62
62
|
KnownCaipNamespace["Bip122"] = "bip122";
|
|
63
63
|
/** Solana compatible chains */
|
|
64
64
|
KnownCaipNamespace["Solana"] = "solana";
|
|
65
|
+
/** Tron compatible chains */
|
|
66
|
+
KnownCaipNamespace["Tron"] = "tron";
|
|
65
67
|
/** EIP-155 compatible chains. */
|
|
66
68
|
KnownCaipNamespace["Eip155"] = "eip155";
|
|
67
69
|
KnownCaipNamespace["Wallet"] = "wallet";
|
package/dist/caip-types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip-types.mjs","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,8BAA8B;AAE3C,OAAO,EAAE,aAAa,EAAE,0BAAsB;AAE9C,MAAM,CAAC,MAAM,mBAAmB,GAC9B,mEAAmE,CAAC;AAEtE,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAExD,MAAM,CAAC,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AAE7D,MAAM,CAAC,MAAM,qBAAqB,GAChC,wHAAwH,CAAC;AAE3H,MAAM,CAAC,MAAM,0BAA0B,GAAG,0BAA0B,CAAC;AAErE,MAAM,CAAC,MAAM,0BAA0B,GAAG,mBAAmB,CAAC;AAE9D,MAAM,CAAC,MAAM,0BAA0B,GAAG,0BAA0B,CAAC;AAErE,MAAM,CAAC,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAE7D,MAAM,CAAC,MAAM,qBAAqB,GAChC,2JAA2J,CAAC;AAE9J,MAAM,CAAC,MAAM,mBAAmB,GAC9B,6LAA6L,CAAC;AAEhM,MAAM,2BAA2B,GAC/B,gMAAgM,CAAC;AAEnM;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAC5C,aAAa,EACb,mBAAmB,CACpB,CAAC;AAGF;;GAEG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,EACxB,SAAwB,EACxB,cAAkC,EAClC,cAAkC,EAClC,OAAoB;IAEpB,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CACb,oCAAoC,oBAAoB,CAAC,QAAQ,EAAE,EAAE,CACtE,CAAC;KACH;IAED,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CACb,oCAAoC,oBAAoB,CAAC,QAAQ,EAAE,EAAE,CACtE,CAAC;KACH;IAED,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE;QACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,0BAA0B,CAAC,QAAQ,EAAE,EAAE,CACjF,CAAC;KACH;IAED,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE;QACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,0BAA0B,CAAC,QAAQ,EAAE,EAAE,CACjF,CAAC;KACH;IAED,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,kCAAkC,mBAAmB,CAAC,QAAQ,EAAE,EAAE,CACnE,CAAC;KACH;IAED,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,cAAc,IAAI,cAAc,IAAI,OAAO,EAAE,CAAC;AACpF,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { is } from '@metamask/superstruct';\n\nimport { definePattern } from './superstruct';\n\nexport const CAIP_CHAIN_ID_REGEX =\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;\n\nexport const CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;\n\nexport const CAIP_ACCOUNT_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})):(?<accountAddress>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ACCOUNT_ADDRESS_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_ASSET_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_ASSET_REFERENCE_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_TOKEN_ID_REGEX = /^[-.%a-zA-Z0-9]{1,78}$/u;\n\nexport const CAIP_ASSET_TYPE_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ASSET_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;\n\nconst CAIP_ASSET_TYPE_OR_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})(\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78}))?$/u;\n\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const CaipChainIdStruct = definePattern<`${string}:${string}`>(\n 'CaipChainId',\n CAIP_CHAIN_ID_REGEX,\n);\nexport type CaipChainId = Infer<typeof CaipChainIdStruct>;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.\n */\nexport const CaipNamespaceStruct = definePattern(\n 'CaipNamespace',\n CAIP_NAMESPACE_REGEX,\n);\nexport type CaipNamespace = Infer<typeof CaipNamespaceStruct>;\n\n/**\n * A CAIP-2 reference, i.e., the second part of a CAIP chain ID.\n */\nexport const CaipReferenceStruct = definePattern(\n 'CaipReference',\n CAIP_REFERENCE_REGEX,\n);\nexport type CaipReference = Infer<typeof CaipReferenceStruct>;\n\n/**\n * A CAIP-10 account ID, i.e., a human-readable namespace, reference, and account address.\n */\nexport const CaipAccountIdStruct =\n definePattern<`${string}:${string}:${string}`>(\n 'CaipAccountId',\n CAIP_ACCOUNT_ID_REGEX,\n );\nexport type CaipAccountId = Infer<typeof CaipAccountIdStruct>;\n\n/**\n * A CAIP-10 account address, i.e., the third part of the CAIP account ID.\n */\nexport const CaipAccountAddressStruct = definePattern(\n 'CaipAccountAddress',\n CAIP_ACCOUNT_ADDRESS_REGEX,\n);\nexport type CaipAccountAddress = Infer<typeof CaipAccountAddressStruct>;\n\n/**\n * A CAIP-19 asset namespace, i.e., a namespace domain of an asset.\n */\nexport const CaipAssetNamespaceStruct = definePattern(\n 'CaipAssetNamespace',\n CAIP_ASSET_NAMESPACE_REGEX,\n);\nexport type CaipAssetNamespace = Infer<typeof CaipAssetNamespaceStruct>;\n\n/**\n * A CAIP-19 asset reference, i.e., an identifier for an asset within a given namespace.\n */\nexport const CaipAssetReferenceStruct = definePattern(\n 'CaipAssetReference',\n CAIP_ASSET_REFERENCE_REGEX,\n);\nexport type CaipAssetReference = Infer<typeof CaipAssetReferenceStruct>;\n\n/**\n * A CAIP-19 asset token ID, i.e., a unique identifier for an addressable asset of a given type\n */\nexport const CaipTokenIdStruct = definePattern(\n 'CaipTokenId',\n CAIP_TOKEN_ID_REGEX,\n);\nexport type CaipTokenId = Infer<typeof CaipTokenIdStruct>;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeStruct =\n definePattern<`${string}:${string}/${string}:${string}`>(\n 'CaipAssetType',\n CAIP_ASSET_TYPE_REGEX,\n );\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.\n */\nexport const CaipAssetIdStruct =\n definePattern<`${string}:${string}/${string}:${string}/${string}`>(\n 'CaipAssetId',\n CAIP_ASSET_ID_REGEX,\n );\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeOrIdStruct = definePattern<\n CaipAssetType | CaipAssetId\n>('CaipAssetTypeOrId', CAIP_ASSET_TYPE_OR_ID_REGEX);\nexport type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;\n\n/** Known CAIP namespaces. */\nexport enum KnownCaipNamespace {\n /** BIP-122 (Bitcoin) compatible chains. */\n Bip122 = 'bip122',\n /** Solana compatible chains */\n Solana = 'solana',\n /** EIP-155 compatible chains. */\n Eip155 = 'eip155',\n Wallet = 'wallet',\n}\n\n/**\n * A CAIP-2 chain ID that is guaranteed to have a known CAIP namespace\n * (@see {@link KnownCaipNamespace}).\n *\n * This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases\n * where the chain namespace must be one of the known standards.\n *\n * @template Namespace - The namespace of the CAIP-2 chain ID. Must be a known namespace specified in {@link KnownCaipNamespace}.\n */\nexport type KnownCaipNamespacedChainId<\n Namespace extends `${KnownCaipNamespace}` = `${KnownCaipNamespace}`,\n> = `${Namespace}:${string}`;\n\n/**\n * Check if the given value is a {@link CaipChainId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipChainId}.\n */\nexport function isCaipChainId(value: unknown): value is CaipChainId {\n return is(value, CaipChainIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipNamespace}.\n */\nexport function isCaipNamespace(value: unknown): value is CaipNamespace {\n return is(value, CaipNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipReference}.\n */\nexport function isCaipReference(value: unknown): value is CaipReference {\n return is(value, CaipReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAccountId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAccountId}.\n */\nexport function isCaipAccountId(value: unknown): value is CaipAccountId {\n return is(value, CaipAccountIdStruct);\n}\n\n/**\n * Check if a value is a {@link CaipAccountAddress}.\n *\n * @param value - The value to validate.\n * @returns True if the value is a valid {@link CaipAccountAddress}.\n */\nexport function isCaipAccountAddress(\n value: unknown,\n): value is CaipAccountAddress {\n return is(value, CaipAccountAddressStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetNamespace}.\n */\nexport function isCaipAssetNamespace(\n value: unknown,\n): value is CaipAssetNamespace {\n return is(value, CaipAssetNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetReference}.\n */\nexport function isCaipAssetReference(\n value: unknown,\n): value is CaipAssetReference {\n return is(value, CaipAssetReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipTokenId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipTokenId}.\n */\nexport function isCaipTokenId(value: unknown): value is CaipTokenId {\n return is(value, CaipTokenIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n\n/**\n * Parse a CAIP-2 chain ID to an object containing the namespace and reference.\n * This validates the CAIP-2 chain ID before parsing it.\n *\n * @param caipChainId - The CAIP-2 chain ID to validate and parse.\n * @returns The parsed CAIP-2 chain ID.\n */\nexport function parseCaipChainId(caipChainId: CaipChainId): {\n namespace: CaipNamespace;\n reference: CaipReference;\n} {\n const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP chain ID.');\n }\n\n return {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n };\n}\n\n/**\n * Parse an CAIP-10 account ID to an object containing the chain ID, parsed chain ID, and account address.\n * This validates the CAIP-10 account ID before parsing it.\n *\n * @param caipAccountId - The CAIP-10 account ID to validate and parse.\n * @returns The parsed CAIP-10 account ID.\n */\nexport function parseCaipAccountId(caipAccountId: CaipAccountId): {\n address: CaipAccountAddress;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ACCOUNT_ID_REGEX.exec(caipAccountId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP account ID.');\n }\n\n return {\n address: match.groups.accountAddress as CaipAccountAddress,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset type to an object containing the chain ID, parsed chain ID,\n * asset namespace, and asset reference\n *\n * This validates the CAIP-19 asset type before parsing it.\n *\n * @param caipAssetType - The CAIP-19 asset type to validate and parse.\n * @returns The parsed CAIP-19 asset type.\n */\nexport function parseCaipAssetType(caipAssetType: CaipAssetType): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_TYPE_REGEX.exec(caipAssetType);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset type.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset ID to an object containing the chain ID, parsed chain ID,\n * asset namespace, asset reference, and token ID.\n *\n * This validates the CAIP-19 asset ID before parsing it.\n *\n * @param caipAssetId - The CAIP-19 asset ID to validate and parse.\n * @returns The parsed CAIP-19 asset ID.\n */\nexport function parseCaipAssetId(caipAssetId: CaipAssetId): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n tokenId: CaipTokenId;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_ID_REGEX.exec(caipAssetId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset ID.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n tokenId: match.groups.tokenId as CaipTokenId,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Chain ID as defined per the CAIP-2\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md}.\n *\n * It defines a way to uniquely identify any blockchain in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identify of a blockchain within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs does not comply with the CAIP-2\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md#syntax}.\n * @returns A CAIP chain ID.\n */\nexport function toCaipChainId(\n namespace: CaipNamespace,\n reference: CaipReference,\n): CaipChainId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}`;\n}\n\n/**\n * Account ID as defined per the CAIP-10\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md}.\n *\n * It defines a way to uniquely identify any blockchain account in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param accountAddress - The address of the blockchain account.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-10\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md#syntax}.\n * @returns A CAIP account ID.\n */\nexport function toCaipAccountId(\n namespace: CaipNamespace,\n reference: CaipReference,\n accountAddress: CaipAccountAddress,\n): CaipAccountId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAccountAddress(accountAddress)) {\n throw new Error(\n `Invalid \"accountAddress\", must match: ${CAIP_ACCOUNT_ADDRESS_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}:${accountAddress}`;\n}\n\n/**\n * Asset Type as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset type.\n */\nexport function toCaipAssetType(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n): CaipAssetType {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}`;\n}\n\n/**\n * Asset ID as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @param tokenId - The unique identifier for an addressable asset of a given type.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset ID.\n */\nexport function toCaipAssetId(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n tokenId: CaipTokenId,\n): CaipAssetId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipTokenId(tokenId)) {\n throw new Error(\n `Invalid \"tokenId\", must match: ${CAIP_TOKEN_ID_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}/${tokenId}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"caip-types.mjs","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,8BAA8B;AAE3C,OAAO,EAAE,aAAa,EAAE,0BAAsB;AAE9C,MAAM,CAAC,MAAM,mBAAmB,GAC9B,mEAAmE,CAAC;AAEtE,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAExD,MAAM,CAAC,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AAE7D,MAAM,CAAC,MAAM,qBAAqB,GAChC,wHAAwH,CAAC;AAE3H,MAAM,CAAC,MAAM,0BAA0B,GAAG,0BAA0B,CAAC;AAErE,MAAM,CAAC,MAAM,0BAA0B,GAAG,mBAAmB,CAAC;AAE9D,MAAM,CAAC,MAAM,0BAA0B,GAAG,0BAA0B,CAAC;AAErE,MAAM,CAAC,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAE7D,MAAM,CAAC,MAAM,qBAAqB,GAChC,2JAA2J,CAAC;AAE9J,MAAM,CAAC,MAAM,mBAAmB,GAC9B,6LAA6L,CAAC;AAEhM,MAAM,2BAA2B,GAC/B,gMAAgM,CAAC;AAEnM;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAC5C,aAAa,EACb,mBAAmB,C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;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,aAAa,CAC3B,SAAwB,EACxB,SAAwB,EACxB,cAAkC,EAClC,cAAkC,EAClC,OAAoB;IAEpB,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CACb,oCAAoC,oBAAoB,CAAC,QAAQ,EAAE,EAAE,CACtE,CAAC;KACH;IAED,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CACb,oCAAoC,oBAAoB,CAAC,QAAQ,EAAE,EAAE,CACtE,CAAC;KACH;IAED,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE;QACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,0BAA0B,CAAC,QAAQ,EAAE,EAAE,CACjF,CAAC;KACH;IAED,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE;QACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,0BAA0B,CAAC,QAAQ,EAAE,EAAE,CACjF,CAAC;KACH;IAED,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,kCAAkC,mBAAmB,CAAC,QAAQ,EAAE,EAAE,CACnE,CAAC;KACH;IAED,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,cAAc,IAAI,cAAc,IAAI,OAAO,EAAE,CAAC;AACpF,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { is } from '@metamask/superstruct';\n\nimport { definePattern } from './superstruct';\n\nexport const CAIP_CHAIN_ID_REGEX =\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;\n\nexport const CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;\n\nexport const CAIP_ACCOUNT_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})):(?<accountAddress>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ACCOUNT_ADDRESS_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_ASSET_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_ASSET_REFERENCE_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_TOKEN_ID_REGEX = /^[-.%a-zA-Z0-9]{1,78}$/u;\n\nexport const CAIP_ASSET_TYPE_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ASSET_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;\n\nconst CAIP_ASSET_TYPE_OR_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})(\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78}))?$/u;\n\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const CaipChainIdStruct = definePattern<`${string}:${string}`>(\n 'CaipChainId',\n CAIP_CHAIN_ID_REGEX,\n);\nexport type CaipChainId = Infer<typeof CaipChainIdStruct>;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.\n */\nexport const CaipNamespaceStruct = definePattern(\n 'CaipNamespace',\n CAIP_NAMESPACE_REGEX,\n);\nexport type CaipNamespace = Infer<typeof CaipNamespaceStruct>;\n\n/**\n * A CAIP-2 reference, i.e., the second part of a CAIP chain ID.\n */\nexport const CaipReferenceStruct = definePattern(\n 'CaipReference',\n CAIP_REFERENCE_REGEX,\n);\nexport type CaipReference = Infer<typeof CaipReferenceStruct>;\n\n/**\n * A CAIP-10 account ID, i.e., a human-readable namespace, reference, and account address.\n */\nexport const CaipAccountIdStruct =\n definePattern<`${string}:${string}:${string}`>(\n 'CaipAccountId',\n CAIP_ACCOUNT_ID_REGEX,\n );\nexport type CaipAccountId = Infer<typeof CaipAccountIdStruct>;\n\n/**\n * A CAIP-10 account address, i.e., the third part of the CAIP account ID.\n */\nexport const CaipAccountAddressStruct = definePattern(\n 'CaipAccountAddress',\n CAIP_ACCOUNT_ADDRESS_REGEX,\n);\nexport type CaipAccountAddress = Infer<typeof CaipAccountAddressStruct>;\n\n/**\n * A CAIP-19 asset namespace, i.e., a namespace domain of an asset.\n */\nexport const CaipAssetNamespaceStruct = definePattern(\n 'CaipAssetNamespace',\n CAIP_ASSET_NAMESPACE_REGEX,\n);\nexport type CaipAssetNamespace = Infer<typeof CaipAssetNamespaceStruct>;\n\n/**\n * A CAIP-19 asset reference, i.e., an identifier for an asset within a given namespace.\n */\nexport const CaipAssetReferenceStruct = definePattern(\n 'CaipAssetReference',\n CAIP_ASSET_REFERENCE_REGEX,\n);\nexport type CaipAssetReference = Infer<typeof CaipAssetReferenceStruct>;\n\n/**\n * A CAIP-19 asset token ID, i.e., a unique identifier for an addressable asset of a given type\n */\nexport const CaipTokenIdStruct = definePattern(\n 'CaipTokenId',\n CAIP_TOKEN_ID_REGEX,\n);\nexport type CaipTokenId = Infer<typeof CaipTokenIdStruct>;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeStruct =\n definePattern<`${string}:${string}/${string}:${string}`>(\n 'CaipAssetType',\n CAIP_ASSET_TYPE_REGEX,\n );\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.\n */\nexport const CaipAssetIdStruct =\n definePattern<`${string}:${string}/${string}:${string}/${string}`>(\n 'CaipAssetId',\n CAIP_ASSET_ID_REGEX,\n );\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeOrIdStruct = definePattern<\n CaipAssetType | CaipAssetId\n>('CaipAssetTypeOrId', CAIP_ASSET_TYPE_OR_ID_REGEX);\nexport type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;\n\n/** Known CAIP namespaces. */\nexport enum KnownCaipNamespace {\n /** BIP-122 (Bitcoin) compatible chains. */\n Bip122 = 'bip122',\n /** Solana compatible chains */\n Solana = 'solana',\n /** Tron compatible chains */\n Tron = 'tron',\n /** EIP-155 compatible chains. */\n Eip155 = 'eip155',\n Wallet = 'wallet',\n}\n\n/**\n * A CAIP-2 chain ID that is guaranteed to have a known CAIP namespace\n * (@see {@link KnownCaipNamespace}).\n *\n * This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases\n * where the chain namespace must be one of the known standards.\n *\n * @template Namespace - The namespace of the CAIP-2 chain ID. Must be a known namespace specified in {@link KnownCaipNamespace}.\n */\nexport type KnownCaipNamespacedChainId<\n Namespace extends `${KnownCaipNamespace}` = `${KnownCaipNamespace}`,\n> = `${Namespace}:${string}`;\n\n/**\n * Check if the given value is a {@link CaipChainId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipChainId}.\n */\nexport function isCaipChainId(value: unknown): value is CaipChainId {\n return is(value, CaipChainIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipNamespace}.\n */\nexport function isCaipNamespace(value: unknown): value is CaipNamespace {\n return is(value, CaipNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipReference}.\n */\nexport function isCaipReference(value: unknown): value is CaipReference {\n return is(value, CaipReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAccountId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAccountId}.\n */\nexport function isCaipAccountId(value: unknown): value is CaipAccountId {\n return is(value, CaipAccountIdStruct);\n}\n\n/**\n * Check if a value is a {@link CaipAccountAddress}.\n *\n * @param value - The value to validate.\n * @returns True if the value is a valid {@link CaipAccountAddress}.\n */\nexport function isCaipAccountAddress(\n value: unknown,\n): value is CaipAccountAddress {\n return is(value, CaipAccountAddressStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetNamespace}.\n */\nexport function isCaipAssetNamespace(\n value: unknown,\n): value is CaipAssetNamespace {\n return is(value, CaipAssetNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetReference}.\n */\nexport function isCaipAssetReference(\n value: unknown,\n): value is CaipAssetReference {\n return is(value, CaipAssetReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipTokenId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipTokenId}.\n */\nexport function isCaipTokenId(value: unknown): value is CaipTokenId {\n return is(value, CaipTokenIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n\n/**\n * Parse a CAIP-2 chain ID to an object containing the namespace and reference.\n * This validates the CAIP-2 chain ID before parsing it.\n *\n * @param caipChainId - The CAIP-2 chain ID to validate and parse.\n * @returns The parsed CAIP-2 chain ID.\n */\nexport function parseCaipChainId(caipChainId: CaipChainId): {\n namespace: CaipNamespace;\n reference: CaipReference;\n} {\n const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP chain ID.');\n }\n\n return {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n };\n}\n\n/**\n * Parse an CAIP-10 account ID to an object containing the chain ID, parsed chain ID, and account address.\n * This validates the CAIP-10 account ID before parsing it.\n *\n * @param caipAccountId - The CAIP-10 account ID to validate and parse.\n * @returns The parsed CAIP-10 account ID.\n */\nexport function parseCaipAccountId(caipAccountId: CaipAccountId): {\n address: CaipAccountAddress;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ACCOUNT_ID_REGEX.exec(caipAccountId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP account ID.');\n }\n\n return {\n address: match.groups.accountAddress as CaipAccountAddress,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset type to an object containing the chain ID, parsed chain ID,\n * asset namespace, and asset reference\n *\n * This validates the CAIP-19 asset type before parsing it.\n *\n * @param caipAssetType - The CAIP-19 asset type to validate and parse.\n * @returns The parsed CAIP-19 asset type.\n */\nexport function parseCaipAssetType(caipAssetType: CaipAssetType): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_TYPE_REGEX.exec(caipAssetType);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset type.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Parse a CAIP-19 asset ID to an object containing the chain ID, parsed chain ID,\n * asset namespace, asset reference, and token ID.\n *\n * This validates the CAIP-19 asset ID before parsing it.\n *\n * @param caipAssetId - The CAIP-19 asset ID to validate and parse.\n * @returns The parsed CAIP-19 asset ID.\n */\nexport function parseCaipAssetId(caipAssetId: CaipAssetId): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n tokenId: CaipTokenId;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_ID_REGEX.exec(caipAssetId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset ID.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n tokenId: match.groups.tokenId as CaipTokenId,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n\n/**\n * Chain ID as defined per the CAIP-2\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md}.\n *\n * It defines a way to uniquely identify any blockchain in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identify of a blockchain within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs does not comply with the CAIP-2\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md#syntax}.\n * @returns A CAIP chain ID.\n */\nexport function toCaipChainId(\n namespace: CaipNamespace,\n reference: CaipReference,\n): CaipChainId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}`;\n}\n\n/**\n * Account ID as defined per the CAIP-10\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md}.\n *\n * It defines a way to uniquely identify any blockchain account in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param accountAddress - The address of the blockchain account.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-10\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md#syntax}.\n * @returns A CAIP account ID.\n */\nexport function toCaipAccountId(\n namespace: CaipNamespace,\n reference: CaipReference,\n accountAddress: CaipAccountAddress,\n): CaipAccountId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAccountAddress(accountAddress)) {\n throw new Error(\n `Invalid \"accountAddress\", must match: ${CAIP_ACCOUNT_ADDRESS_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}:${accountAddress}`;\n}\n\n/**\n * Asset Type as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset type.\n */\nexport function toCaipAssetType(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n): CaipAssetType {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}`;\n}\n\n/**\n * Asset ID as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @param tokenId - The unique identifier for an addressable asset of a given type.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset ID.\n */\nexport function toCaipAssetId(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n tokenId: CaipTokenId,\n): CaipAssetId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipTokenId(tokenId)) {\n throw new Error(\n `Invalid \"tokenId\", must match: ${CAIP_TOKEN_ID_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}/${tokenId}`;\n}\n"]}
|
package/package.json
CHANGED