@metamask/utils 8.1.0 → 8.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -1
- package/dist/assert.js +16 -0
- package/dist/assert.js.map +1 -0
- package/dist/assert.mjs +16 -0
- package/dist/assert.mjs.map +1 -0
- package/dist/base64.js +11 -0
- package/dist/base64.js.map +1 -0
- package/dist/base64.mjs +11 -0
- package/dist/base64.mjs.map +1 -0
- package/dist/bytes.js +43 -0
- package/dist/bytes.js.map +1 -0
- package/dist/bytes.mjs +43 -0
- package/dist/bytes.mjs.map +1 -0
- package/dist/caip-types.js +40 -0
- package/dist/caip-types.js.map +1 -0
- package/dist/caip-types.mjs +40 -0
- package/dist/caip-types.mjs.map +1 -0
- package/dist/checksum.js +12 -0
- package/dist/checksum.js.map +1 -0
- package/dist/checksum.mjs +12 -0
- package/dist/checksum.mjs.map +1 -0
- package/dist/chunk-2LBGT4GH.js +15 -0
- package/dist/chunk-2LBGT4GH.js.map +1 -0
- package/dist/chunk-2TBCL6EF.js +1 -0
- package/dist/chunk-2TBCL6EF.js.map +1 -0
- package/dist/chunk-3W5G4CYI.js +25 -0
- package/dist/chunk-3W5G4CYI.js.map +1 -0
- package/dist/chunk-4D6XQBHA.js +69 -0
- package/dist/chunk-4D6XQBHA.js.map +1 -0
- package/dist/chunk-4RMX5YWE.js +34 -0
- package/dist/chunk-4RMX5YWE.js.map +1 -0
- package/dist/chunk-52OU772R.mjs +122 -0
- package/dist/chunk-52OU772R.mjs.map +1 -0
- package/dist/chunk-6C35XQOF.mjs +257 -0
- package/dist/chunk-6C35XQOF.mjs.map +1 -0
- package/dist/chunk-6NZW4WK4.js +35 -0
- package/dist/chunk-6NZW4WK4.js.map +1 -0
- package/dist/chunk-6ZDHSOUV.js +59 -0
- package/dist/chunk-6ZDHSOUV.js.map +1 -0
- package/dist/chunk-74DGVJVE.mjs +59 -0
- package/dist/chunk-74DGVJVE.mjs.map +1 -0
- package/dist/chunk-AY6FDCBT.mjs +1 -0
- package/dist/chunk-AY6FDCBT.mjs.map +1 -0
- package/dist/chunk-BFQDMI3M.js +122 -0
- package/dist/chunk-BFQDMI3M.js.map +1 -0
- package/dist/chunk-DHVKFDHQ.js +95 -0
- package/dist/chunk-DHVKFDHQ.js.map +1 -0
- package/dist/chunk-DYMCEQIV.mjs +1 -0
- package/dist/chunk-DYMCEQIV.mjs.map +1 -0
- package/dist/chunk-E4C7EW4R.js +16 -0
- package/dist/chunk-E4C7EW4R.js.map +1 -0
- package/dist/chunk-EQMZL4XU.js +1 -0
- package/dist/chunk-EQMZL4XU.js.map +1 -0
- package/dist/chunk-GZS3IQBZ.mjs +16 -0
- package/dist/chunk-GZS3IQBZ.mjs.map +1 -0
- package/dist/chunk-H4YFDLB7.mjs +70 -0
- package/dist/chunk-H4YFDLB7.mjs.map +1 -0
- package/dist/chunk-I575FZFH.mjs +1 -0
- package/dist/chunk-I575FZFH.mjs.map +1 -0
- package/dist/chunk-IZC266HS.js +55 -0
- package/dist/chunk-IZC266HS.js.map +1 -0
- package/dist/chunk-JPAL7Q5S.mjs +90 -0
- package/dist/chunk-JPAL7Q5S.mjs.map +1 -0
- package/dist/chunk-LC2CRSWD.js +1 -0
- package/dist/chunk-LC2CRSWD.js.map +1 -0
- package/dist/chunk-NQMRFZHB.mjs +35 -0
- package/dist/chunk-NQMRFZHB.mjs.map +1 -0
- package/dist/chunk-O3EIM33O.mjs +95 -0
- package/dist/chunk-O3EIM33O.mjs.map +1 -0
- package/dist/chunk-OLLG4H35.js +257 -0
- package/dist/chunk-OLLG4H35.js.map +1 -0
- package/dist/chunk-QEPVHEP7.js +273 -0
- package/dist/chunk-QEPVHEP7.js.map +1 -0
- package/dist/chunk-QVEKZRZ2.js +70 -0
- package/dist/chunk-QVEKZRZ2.js.map +1 -0
- package/dist/chunk-RIRDOQPX.mjs +15 -0
- package/dist/chunk-RIRDOQPX.mjs.map +1 -0
- package/dist/chunk-RKRGAFXY.js +1 -0
- package/dist/chunk-RKRGAFXY.js.map +1 -0
- package/dist/chunk-ROQSKDP5.mjs +69 -0
- package/dist/chunk-ROQSKDP5.mjs.map +1 -0
- package/dist/chunk-RRYOWRCV.mjs +1 -0
- package/dist/chunk-RRYOWRCV.mjs.map +1 -0
- package/dist/chunk-S3UHBN2Z.mjs +44 -0
- package/dist/chunk-S3UHBN2Z.mjs.map +1 -0
- package/dist/chunk-TGOMTREC.mjs +75 -0
- package/dist/chunk-TGOMTREC.mjs.map +1 -0
- package/dist/chunk-THNLGEXV.mjs +34 -0
- package/dist/chunk-THNLGEXV.mjs.map +1 -0
- package/dist/chunk-U7ZUGCE7.js +75 -0
- package/dist/chunk-U7ZUGCE7.js.map +1 -0
- package/dist/chunk-UOTVU7OQ.js +1 -0
- package/dist/chunk-UOTVU7OQ.js.map +1 -0
- package/dist/chunk-VA2DRBDE.mjs +273 -0
- package/dist/chunk-VA2DRBDE.mjs.map +1 -0
- package/dist/chunk-VFXTVNXN.js +44 -0
- package/dist/chunk-VFXTVNXN.js.map +1 -0
- package/dist/chunk-WA4DHIND.mjs +1 -0
- package/dist/chunk-WA4DHIND.mjs.map +1 -0
- package/dist/chunk-X66SUIEF.mjs +25 -0
- package/dist/chunk-X66SUIEF.mjs.map +1 -0
- package/dist/chunk-XYGUOY6N.mjs +55 -0
- package/dist/chunk-XYGUOY6N.mjs.map +1 -0
- package/dist/chunk-Z2RGWDD7.js +90 -0
- package/dist/chunk-Z2RGWDD7.js.map +1 -0
- package/dist/coercers.js +18 -0
- package/dist/coercers.js.map +1 -0
- package/dist/coercers.mjs +18 -0
- package/dist/coercers.mjs.map +1 -0
- package/dist/collections.js +10 -0
- package/dist/collections.js.map +1 -0
- package/dist/collections.mjs +10 -0
- package/dist/collections.mjs.map +1 -0
- package/dist/encryption-types.js +2 -0
- package/dist/encryption-types.js.map +1 -0
- package/dist/encryption-types.mjs +2 -0
- package/dist/encryption-types.mjs.map +1 -0
- package/dist/errors.js +17 -0
- package/dist/errors.js.map +1 -0
- package/dist/errors.mjs +17 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/fs.js +26 -0
- package/dist/fs.js.map +1 -0
- package/dist/fs.mjs +26 -0
- package/dist/fs.mjs.map +1 -0
- package/dist/hex.js +35 -0
- package/dist/hex.js.map +1 -0
- package/dist/hex.mjs +35 -0
- package/dist/hex.mjs.map +1 -0
- package/dist/index.js +289 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +289 -0
- package/dist/index.mjs.map +1 -0
- package/dist/json.js +75 -0
- package/dist/json.js.map +1 -0
- package/dist/json.mjs +75 -0
- package/dist/json.mjs.map +1 -0
- package/dist/keyring.js +2 -0
- package/dist/keyring.js.map +1 -0
- package/dist/keyring.mjs +2 -0
- package/dist/keyring.mjs.map +1 -0
- package/dist/logging.js +10 -0
- package/dist/logging.js.map +1 -0
- package/dist/logging.mjs +10 -0
- package/dist/logging.mjs.map +1 -0
- package/dist/misc.js +28 -0
- package/dist/misc.js.map +1 -0
- package/dist/misc.mjs +28 -0
- package/dist/misc.mjs.map +1 -0
- package/dist/node.js +309 -0
- package/dist/node.js.map +1 -0
- package/dist/node.mjs +309 -0
- package/dist/node.mjs.map +1 -0
- package/dist/number.js +18 -0
- package/dist/number.js.map +1 -0
- package/dist/number.mjs +18 -0
- package/dist/number.mjs.map +1 -0
- package/dist/opaque.js +2 -0
- package/dist/opaque.js.map +1 -0
- package/dist/opaque.mjs +2 -0
- package/dist/opaque.mjs.map +1 -0
- package/dist/time.js +12 -0
- package/dist/time.js.map +1 -0
- package/dist/time.mjs +12 -0
- package/dist/time.mjs.map +1 -0
- package/dist/transaction-types.js +2 -0
- package/dist/transaction-types.js.map +1 -0
- package/dist/transaction-types.mjs +2 -0
- package/dist/transaction-types.mjs.map +1 -0
- package/dist/types/assert.d.ts.map +1 -1
- package/dist/types/bytes.d.ts +14 -0
- package/dist/types/bytes.d.ts.map +1 -1
- package/dist/types/errors.d.ts +58 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/fs.d.ts +133 -0
- package/dist/types/fs.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/json.d.ts +83 -44
- package/dist/types/json.d.ts.map +1 -1
- package/dist/types/node.d.ts +3 -0
- package/dist/types/node.d.ts.map +1 -0
- package/dist/versions.js +27 -0
- package/dist/versions.js.map +1 -0
- package/dist/versions.mjs +27 -0
- package/dist/versions.mjs.map +1 -0
- package/package.json +22 -21
- package/dist/cjs/assert.js +0 -116
- package/dist/cjs/assert.js.map +0 -1
- package/dist/cjs/base64.js +0 -32
- package/dist/cjs/base64.js.map +0 -1
- package/dist/cjs/bytes.js +0 -255
- package/dist/cjs/bytes.js.map +0 -1
- package/dist/cjs/caip-types.js +0 -115
- package/dist/cjs/caip-types.js.map +0 -1
- package/dist/cjs/checksum.js +0 -17
- package/dist/cjs/checksum.js.map +0 -1
- package/dist/cjs/coercers.js +0 -96
- package/dist/cjs/coercers.js.map +0 -1
- package/dist/cjs/collections.js +0 -157
- package/dist/cjs/collections.js.map +0 -1
- package/dist/cjs/encryption-types.js +0 -6
- package/dist/cjs/encryption-types.js.map +0 -1
- package/dist/cjs/hex.js +0 -107
- package/dist/cjs/hex.js.map +0 -1
- package/dist/cjs/index.js +0 -37
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/json.js +0 -265
- package/dist/cjs/json.js.map +0 -1
- package/dist/cjs/keyring.js +0 -6
- package/dist/cjs/keyring.js.map +0 -1
- package/dist/cjs/logging.js +0 -33
- package/dist/cjs/logging.js.map +0 -1
- package/dist/cjs/misc.js +0 -111
- package/dist/cjs/misc.js.map +0 -1
- package/dist/cjs/number.js +0 -52
- package/dist/cjs/number.js.map +0 -1
- package/dist/cjs/opaque.js +0 -8
- package/dist/cjs/opaque.js.map +0 -1
- package/dist/cjs/time.js +0 -63
- package/dist/cjs/time.js.map +0 -1
- package/dist/cjs/transaction-types.js +0 -6
- package/dist/cjs/transaction-types.js.map +0 -1
- package/dist/cjs/versions.js +0 -79
- package/dist/cjs/versions.js.map +0 -1
- package/dist/esm/assert.js +0 -133
- package/dist/esm/assert.js.map +0 -1
- package/dist/esm/base64.js +0 -28
- package/dist/esm/base64.js.map +0 -1
- package/dist/esm/bytes.js +0 -334
- package/dist/esm/bytes.js.map +0 -1
- package/dist/esm/caip-types.js +0 -99
- package/dist/esm/caip-types.js.map +0 -1
- package/dist/esm/checksum.js +0 -7
- package/dist/esm/checksum.js.map +0 -1
- package/dist/esm/coercers.js +0 -153
- package/dist/esm/coercers.js.map +0 -1
- package/dist/esm/collections.js +0 -140
- package/dist/esm/collections.js.map +0 -1
- package/dist/esm/encryption-types.js +0 -3
- package/dist/esm/encryption-types.js.map +0 -1
- package/dist/esm/hex.js +0 -108
- package/dist/esm/hex.js.map +0 -1
- package/dist/esm/index.js +0 -20
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/json.js +0 -303
- package/dist/esm/json.js.map +0 -1
- package/dist/esm/keyring.js +0 -3
- package/dist/esm/keyring.js.map +0 -1
- package/dist/esm/logging.js +0 -34
- package/dist/esm/logging.js.map +0 -1
- package/dist/esm/misc.js +0 -129
- package/dist/esm/misc.js.map +0 -1
- package/dist/esm/number.js +0 -92
- package/dist/esm/number.js.map +0 -1
- package/dist/esm/opaque.js +0 -5
- package/dist/esm/opaque.js.map +0 -1
- package/dist/esm/package.json +0 -1
- package/dist/esm/time.js +0 -53
- package/dist/esm/time.js.map +0 -1
- package/dist/esm/transaction-types.js +0 -3
- package/dist/esm/transaction-types.js.map +0 -1
- package/dist/esm/versions.js +0 -78
- package/dist/esm/versions.js.map +0 -1
- package/dist/types/caip-types.test-d.d.ts +0 -2
- package/dist/types/caip-types.test-d.d.ts.map +0 -1
- package/dist/types/hex.test-d.d.ts +0 -2
- package/dist/types/hex.test-d.d.ts.map +0 -1
- package/dist/types/json.test-d.d.ts +0 -2
- package/dist/types/json.test-d.d.ts.map +0 -1
- package/dist/types/misc.test-d.d.ts +0 -2
- package/dist/types/misc.test-d.d.ts.map +0 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/misc.ts
|
|
2
|
+
function isNonEmptyArray(value) {
|
|
3
|
+
return Array.isArray(value) && value.length > 0;
|
|
4
|
+
}
|
|
5
|
+
function isNullOrUndefined(value) {
|
|
6
|
+
return value === null || value === void 0;
|
|
7
|
+
}
|
|
8
|
+
function isObject(value) {
|
|
9
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
var hasProperty = (objectToCheck, name) => Object.hasOwnProperty.call(objectToCheck, name);
|
|
12
|
+
function getKnownPropertyNames(object) {
|
|
13
|
+
return Object.getOwnPropertyNames(object);
|
|
14
|
+
}
|
|
15
|
+
var JsonSize = /* @__PURE__ */ ((JsonSize2) => {
|
|
16
|
+
JsonSize2[JsonSize2["Null"] = 4] = "Null";
|
|
17
|
+
JsonSize2[JsonSize2["Comma"] = 1] = "Comma";
|
|
18
|
+
JsonSize2[JsonSize2["Wrapper"] = 1] = "Wrapper";
|
|
19
|
+
JsonSize2[JsonSize2["True"] = 4] = "True";
|
|
20
|
+
JsonSize2[JsonSize2["False"] = 5] = "False";
|
|
21
|
+
JsonSize2[JsonSize2["Quote"] = 1] = "Quote";
|
|
22
|
+
JsonSize2[JsonSize2["Colon"] = 1] = "Colon";
|
|
23
|
+
JsonSize2[JsonSize2["Date"] = 24] = "Date";
|
|
24
|
+
return JsonSize2;
|
|
25
|
+
})(JsonSize || {});
|
|
26
|
+
var ESCAPE_CHARACTERS_REGEXP = /"|\\|\n|\r|\t/gu;
|
|
27
|
+
function isPlainObject(value) {
|
|
28
|
+
if (typeof value !== "object" || value === null) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
let proto = value;
|
|
33
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
34
|
+
proto = Object.getPrototypeOf(proto);
|
|
35
|
+
}
|
|
36
|
+
return Object.getPrototypeOf(value) === proto;
|
|
37
|
+
} catch (_) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function isASCII(character) {
|
|
42
|
+
return character.charCodeAt(0) <= 127;
|
|
43
|
+
}
|
|
44
|
+
function calculateStringSize(value) {
|
|
45
|
+
const size = value.split("").reduce((total, character) => {
|
|
46
|
+
if (isASCII(character)) {
|
|
47
|
+
return total + 1;
|
|
48
|
+
}
|
|
49
|
+
return total + 2;
|
|
50
|
+
}, 0);
|
|
51
|
+
return size + (_nullishCoalesce(value.match(ESCAPE_CHARACTERS_REGEXP), () => ( []))).length;
|
|
52
|
+
}
|
|
53
|
+
function calculateNumberSize(value) {
|
|
54
|
+
return value.toString().length;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
exports.isNonEmptyArray = isNonEmptyArray; exports.isNullOrUndefined = isNullOrUndefined; exports.isObject = isObject; exports.hasProperty = hasProperty; exports.getKnownPropertyNames = getKnownPropertyNames; exports.JsonSize = JsonSize; exports.ESCAPE_CHARACTERS_REGEXP = ESCAPE_CHARACTERS_REGEXP; exports.isPlainObject = isPlainObject; exports.isASCII = isASCII; exports.calculateStringSize = calculateStringSize; exports.calculateNumberSize = calculateNumberSize;
|
|
70
|
+
//# sourceMappingURL=chunk-QVEKZRZ2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/misc.ts"],"names":["JsonSize"],"mappings":";AAiDO,SAAS,gBACd,OACiC;AACjC,SAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS;AAChD;AAQO,SAAS,kBAAkB,OAA2C;AAC3E,SAAO,UAAU,QAAQ,UAAU;AACrC;AASO,SAAS,SAAS,OAAwC;AAC/D,SAAO,QAAQ,KAAK,KAAK,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAcO,IAAM,cAAc,CAKzB,eACA,SAKK,OAAO,eAAe,KAAK,eAAe,IAAI;AAa9C,SAAS,sBACd,QACO;AACP,SAAO,OAAO,oBAAoB,MAAM;AAC1C;AAOO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,aAAU,KAAV;AACA,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,WAAQ,KAAR;AAEA,EAAAA,oBAAA,UAAO,MAAP;AATU,SAAAA;AAAA,GAAA;AAeL,IAAM,2BAA2B;AASjC,SAAS,cAAc,OAAsC;AAClE,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AAEA,MAAI;AACF,QAAI,QAAQ;AACZ,WAAO,OAAO,eAAe,KAAK,MAAM,MAAM;AAC5C,cAAQ,OAAO,eAAe,KAAK;AAAA,IACrC;AAEA,WAAO,OAAO,eAAe,KAAK,MAAM;AAAA,EAC1C,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;AAQO,SAAS,QAAQ,WAAmB;AACzC,SAAO,UAAU,WAAW,CAAC,KAAK;AACpC;AAQO,SAAS,oBAAoB,OAAuB;AACzD,QAAM,OAAO,MAAM,MAAM,EAAE,EAAE,OAAO,CAAC,OAAO,cAAc;AACxD,QAAI,QAAQ,SAAS,GAAG;AACtB,aAAO,QAAQ;AAAA,IACjB;AACA,WAAO,QAAQ;AAAA,EACjB,GAAG,CAAC;AAGJ,SAAO,QAAQ,MAAM,MAAM,wBAAwB,KAAK,CAAC,GAAG;AAC9D;AAQO,SAAS,oBAAoB,OAAuB;AACzD,SAAO,MAAM,SAAS,EAAE;AAC1B","sourcesContent":["//\n// Types\n//\n\n/**\n * Makes every specified property of the specified object type mutable.\n *\n * @template ObjectValue - The object whose readonly properties to make mutable.\n * @template TargetKey - The property key(s) to make mutable.\n */\nexport type Mutable<\n ObjectValue extends Record<string, unknown>,\n TargetKey extends keyof ObjectValue,\n> = {\n -readonly [Key in keyof Pick<ObjectValue, TargetKey>]: ObjectValue[Key];\n} & {\n [Key in keyof Omit<ObjectValue, TargetKey>]: ObjectValue[Key];\n};\n\n/**\n * Useful for representing some value that _might_ be present and / or complete.\n *\n * @template Value - The value that might be present or complete.\n */\nexport type PartialOrAbsent<Value> = Partial<Value> | null | undefined;\n\n/**\n * Like {@link Array}, but always non-empty.\n *\n * @template Element - The non-empty array member type.\n */\nexport type NonEmptyArray<Element> = [Element, ...Element[]];\n\n/**\n * A JavaScript object that is not `null`, a function, or an array.\n */\nexport type RuntimeObject = Record<PropertyKey, unknown>;\n\n//\n// Type Guards\n//\n\n/**\n * A {@link NonEmptyArray} type guard.\n *\n * @template Element - The non-empty array member type.\n * @param value - The value to check.\n * @returns Whether the value is a non-empty array.\n */\nexport function isNonEmptyArray<Element>(\n value: Element[],\n): value is NonEmptyArray<Element> {\n return Array.isArray(value) && value.length > 0;\n}\n\n/**\n * Type guard for \"nullishness\".\n *\n * @param value - Any value.\n * @returns `true` if the value is null or undefined, `false` otherwise.\n */\nexport function isNullOrUndefined(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n\n/**\n * A type guard for {@link RuntimeObject}.\n *\n * @param value - The value to check.\n * @returns Whether the specified value has a runtime type of `object` and is\n * neither `null` nor an `Array`.\n */\nexport function isObject(value: unknown): value is RuntimeObject {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value);\n}\n\n//\n// Other utility functions\n//\n\n/**\n * A type guard for ensuring an object has a property.\n *\n * @param objectToCheck - The object to check.\n * @param name - The property name to check for.\n * @returns Whether the specified object has an own property with the specified\n * name, regardless of whether it is enumerable or not.\n */\nexport const hasProperty = <\n // eslint-disable-next-line @typescript-eslint/ban-types\n ObjectToCheck extends Object,\n Property extends PropertyKey,\n>(\n objectToCheck: ObjectToCheck,\n name: Property,\n): objectToCheck is ObjectToCheck &\n Record<\n Property,\n Property extends keyof ObjectToCheck ? ObjectToCheck[Property] : unknown\n > => Object.hasOwnProperty.call(objectToCheck, name);\n\n/**\n * `Object.getOwnPropertyNames()` is intentionally generic: it returns the\n * immediate property names of an object, but it cannot make guarantees about\n * the contents of that object, so the type of the property names is merely\n * `string[]`. While this is technically accurate, it is also unnecessary if we\n * have an object with a type that we own (such as an enum).\n *\n * @param object - The plain object.\n * @returns The own property names of the object which are assigned a type\n * derived from the object itself.\n */\nexport function getKnownPropertyNames<Key extends PropertyKey>(\n object: Partial<Record<Key, any>>,\n): Key[] {\n return Object.getOwnPropertyNames(object) as Key[];\n}\n\nexport type PlainObject = Record<number | string | symbol, unknown>;\n\n/**\n * Predefined sizes (in Bytes) of specific parts of JSON structure.\n */\nexport enum JsonSize {\n Null = 4,\n Comma = 1,\n Wrapper = 1,\n True = 4,\n False = 5,\n Quote = 1,\n Colon = 1,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n Date = 24,\n}\n\n/**\n * Regular expression with pattern matching for (special) escaped characters.\n */\nexport const ESCAPE_CHARACTERS_REGEXP = /\"|\\\\|\\n|\\r|\\t/gu;\n\n/**\n * Check if the value is plain object.\n *\n * @param value - Value to be checked.\n * @returns True if an object is the plain JavaScript object,\n * false if the object is not plain (e.g. function).\n */\nexport function isPlainObject(value: unknown): value is PlainObject {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n\n try {\n let proto = value;\n while (Object.getPrototypeOf(proto) !== null) {\n proto = Object.getPrototypeOf(proto);\n }\n\n return Object.getPrototypeOf(value) === proto;\n } catch (_) {\n return false;\n }\n}\n\n/**\n * Check if character is ASCII.\n *\n * @param character - Character.\n * @returns True if a character code is ASCII, false if not.\n */\nexport function isASCII(character: string) {\n return character.charCodeAt(0) <= 127;\n}\n\n/**\n * Calculate string size.\n *\n * @param value - String value to calculate size.\n * @returns Number of bytes used to store whole string value.\n */\nexport function calculateStringSize(value: string): number {\n const size = value.split('').reduce((total, character) => {\n if (isASCII(character)) {\n return total + 1;\n }\n return total + 2;\n }, 0);\n\n // Also detect characters that need backslash escape\n return size + (value.match(ESCAPE_CHARACTERS_REGEXP) ?? []).length;\n}\n\n/**\n * Calculate size of a number ofter JSON serialization.\n *\n * @param value - Number value to calculate size.\n * @returns Number of bytes used to store whole number in JSON.\n */\nexport function calculateNumberSize(value: number): number {\n return value.toString().length;\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/logging.ts
|
|
2
|
+
import debug from "debug";
|
|
3
|
+
var globalLogger = debug("metamask");
|
|
4
|
+
function createProjectLogger(projectName) {
|
|
5
|
+
return globalLogger.extend(projectName);
|
|
6
|
+
}
|
|
7
|
+
function createModuleLogger(projectLogger, moduleName) {
|
|
8
|
+
return projectLogger.extend(moduleName);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
createProjectLogger,
|
|
13
|
+
createModuleLogger
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=chunk-RIRDOQPX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/logging.ts"],"sourcesContent":["import type { Debugger } from 'debug';\nimport debug from 'debug';\n\nconst globalLogger = debug('metamask');\n\n/**\n * Creates a logger via the `debug` library whose log messages will be tagged\n * using the name of your project. By default, such messages will be\n * suppressed, but you can reveal them by setting the `DEBUG` environment\n * variable to `metamask:<projectName>`. You can also set this variable to\n * `metamask:*` if you want to see log messages from all MetaMask projects that\n * are also using this function to create their loggers.\n *\n * @param projectName - The name of your project. This should be the name of\n * your NPM package if you're developing one.\n * @returns An instance of `debug`.\n */\nexport function createProjectLogger(projectName: string): Debugger {\n return globalLogger.extend(projectName);\n}\n\n/**\n * Creates a logger via the `debug` library which is derived from the logger for\n * the whole project whose log messages will be tagged using the name of your\n * module. By default, such messages will be suppressed, but you can reveal them\n * by setting the `DEBUG` environment variable to\n * `metamask:<projectName>:<moduleName>`. You can also set this variable to\n * `metamask:<projectName>:*` if you want to see log messages from the project,\n * or `metamask:*` if you want to see log messages from all MetaMask projects.\n *\n * @param projectLogger - The logger created via {@link createProjectLogger}.\n * @param moduleName - The name of your module. You could use the name of the\n * file where you're using this logger or some other name.\n * @returns An instance of `debug`.\n */\nexport function createModuleLogger(\n projectLogger: Debugger,\n moduleName: string,\n): Debugger {\n return projectLogger.extend(moduleName);\n}\n"],"mappings":";AACA,OAAO,WAAW;AAElB,IAAM,eAAe,MAAM,UAAU;AAc9B,SAAS,oBAAoB,aAA+B;AACjE,SAAO,aAAa,OAAO,WAAW;AACxC;AAgBO,SAAS,mBACd,eACA,YACU;AACV,SAAO,cAAc,OAAO,UAAU;AACxC;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";//# sourceMappingURL=chunk-RKRGAFXY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertStruct
|
|
3
|
+
} from "./chunk-74DGVJVE.mjs";
|
|
4
|
+
|
|
5
|
+
// src/versions.ts
|
|
6
|
+
import {
|
|
7
|
+
gt as gtSemver,
|
|
8
|
+
gtr as gtrSemver,
|
|
9
|
+
satisfies as satisfiesSemver,
|
|
10
|
+
valid as validSemVerVersion,
|
|
11
|
+
validRange as validSemVerRange
|
|
12
|
+
} from "semver";
|
|
13
|
+
import { is, refine, string } from "superstruct";
|
|
14
|
+
var VersionStruct = refine(
|
|
15
|
+
string(),
|
|
16
|
+
"Version",
|
|
17
|
+
(value) => {
|
|
18
|
+
if (validSemVerVersion(value) === null) {
|
|
19
|
+
return `Expected SemVer version, got "${value}"`;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
var VersionRangeStruct = refine(
|
|
25
|
+
string(),
|
|
26
|
+
"Version range",
|
|
27
|
+
(value) => {
|
|
28
|
+
if (validSemVerRange(value) === null) {
|
|
29
|
+
return `Expected SemVer range, got "${value}"`;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
function isValidSemVerVersion(version) {
|
|
35
|
+
return is(version, VersionStruct);
|
|
36
|
+
}
|
|
37
|
+
function isValidSemVerRange(versionRange) {
|
|
38
|
+
return is(versionRange, VersionRangeStruct);
|
|
39
|
+
}
|
|
40
|
+
function assertIsSemVerVersion(version) {
|
|
41
|
+
assertStruct(version, VersionStruct);
|
|
42
|
+
}
|
|
43
|
+
function assertIsSemVerRange(range) {
|
|
44
|
+
assertStruct(range, VersionRangeStruct);
|
|
45
|
+
}
|
|
46
|
+
function gtVersion(version1, version2) {
|
|
47
|
+
return gtSemver(version1, version2);
|
|
48
|
+
}
|
|
49
|
+
function gtRange(version, range) {
|
|
50
|
+
return gtrSemver(version, range);
|
|
51
|
+
}
|
|
52
|
+
function satisfiesVersionRange(version, versionRange) {
|
|
53
|
+
return satisfiesSemver(version, versionRange, {
|
|
54
|
+
includePrerelease: true
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
VersionStruct,
|
|
60
|
+
VersionRangeStruct,
|
|
61
|
+
isValidSemVerVersion,
|
|
62
|
+
isValidSemVerRange,
|
|
63
|
+
assertIsSemVerVersion,
|
|
64
|
+
assertIsSemVerRange,
|
|
65
|
+
gtVersion,
|
|
66
|
+
gtRange,
|
|
67
|
+
satisfiesVersionRange
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=chunk-ROQSKDP5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/versions.ts"],"sourcesContent":["import {\n gt as gtSemver,\n gtr as gtrSemver,\n satisfies as satisfiesSemver,\n valid as validSemVerVersion,\n validRange as validSemVerRange,\n} from 'semver';\nimport type { Struct } from 'superstruct';\nimport { is, refine, string } from 'superstruct';\n\nimport { assertStruct } from './assert';\nimport type { Opaque } from './opaque';\n\n/**\n * {@link https://codemix.com/opaque-types-in-javascript/ Opaque} type for SemVer ranges.\n *\n * @example Use {@link assertIsSemVerRange} and {@link isValidSemVerRange} to cast to proper type.\n * ```typescript\n * const unsafeRange: string = dataFromUser();\n * assertIsSemVerRange(unsafeRange);\n * unsafeRange\n * // ^? SemVerRange\n * ```\n * @example If you know what you're doing and want to side-step type safety, casting from a string works correctly.\n * ```typescript\n * const unsafeRange: string = dataFromUser();\n * unsafeRange as SemVerRange;\n * // ^? SemVerRange\n * ```\n * @see {@link assertIsSemVerRange}\n * @see {@link isValidSemVerRange}\n */\nexport type SemVerRange = Opaque<string, typeof semVerRange>;\ndeclare const semVerRange: unique symbol;\n\n/**\n * {@link https://codemix.com/opaque-types-in-javascript/ Opaque} type for singular SemVer version.\n *\n * @example Use {@link assertIsSemVerVersion} and {@link isValidSemVerVersion} to cast to proper type.\n * ```typescript\n * const unsafeVersion: string = dataFromUser();\n * assertIsSemVerVersion(unsafeRange);\n * unsafeVersion\n * // ^? SemVerVersion\n * ```\n * @example If you know what you're doing and want to side-step type safety, casting from a string works correctly.\n * ```typescript\n * const unsafeVersion: string = dataFromUser();\n * unsafeRange as SemVerVersion;\n * // ^? SemVerVersion\n * ```\n * @see {@link assertIsSemVerVersion}\n * @see {@link isValidSemVerVersion}\n */\nexport type SemVerVersion = Opaque<string, typeof semVerVersion>;\ndeclare const semVerVersion: unique symbol;\n\n/**\n * A struct for validating a version string.\n */\nexport const VersionStruct = refine<SemVerVersion, null>(\n string() as unknown as Struct<SemVerVersion, null>,\n 'Version',\n (value) => {\n if (validSemVerVersion(value) === null) {\n return `Expected SemVer version, got \"${value}\"`;\n }\n return true;\n },\n);\n\nexport const VersionRangeStruct = refine<SemVerRange, null>(\n string() as unknown as Struct<SemVerRange, null>,\n 'Version range',\n (value) => {\n if (validSemVerRange(value) === null) {\n return `Expected SemVer range, got \"${value}\"`;\n }\n return true;\n },\n);\n\n/**\n * Checks whether a SemVer version is valid.\n *\n * @param version - A potential version.\n * @returns `true` if the version is valid, and `false` otherwise.\n */\nexport function isValidSemVerVersion(\n version: unknown,\n): version is SemVerVersion {\n return is(version, VersionStruct);\n}\n\n/**\n * Checks whether a SemVer version range is valid.\n *\n * @param versionRange - A potential version range.\n * @returns `true` if the version range is valid, and `false` otherwise.\n */\nexport function isValidSemVerRange(\n versionRange: unknown,\n): versionRange is SemVerRange {\n return is(versionRange, VersionRangeStruct);\n}\n\n/**\n * Asserts that a value is a valid concrete SemVer version.\n *\n * @param version - A potential SemVer concrete version.\n */\nexport function assertIsSemVerVersion(\n version: unknown,\n): asserts version is SemVerVersion {\n assertStruct(version, VersionStruct);\n}\n\n/**\n * Asserts that a value is a valid SemVer range.\n *\n * @param range - A potential SemVer range.\n */\nexport function assertIsSemVerRange(\n range: unknown,\n): asserts range is SemVerRange {\n assertStruct(range, VersionRangeStruct);\n}\n\n/**\n * Checks whether a SemVer version is greater than another.\n *\n * @param version1 - The left-hand version.\n * @param version2 - The right-hand version.\n * @returns `version1 > version2`.\n */\nexport function gtVersion(\n version1: SemVerVersion,\n version2: SemVerVersion,\n): boolean {\n return gtSemver(version1, version2);\n}\n\n/**\n * Checks whether a SemVer version is greater than all possibilities in a range.\n *\n * @param version - A SemvVer version.\n * @param range - The range to check against.\n * @returns `version > range`.\n */\nexport function gtRange(version: SemVerVersion, range: SemVerRange): boolean {\n return gtrSemver(version, range);\n}\n\n/**\n * Returns whether a SemVer version satisfies a SemVer range.\n *\n * @param version - The SemVer version to check.\n * @param versionRange - The SemVer version range to check against.\n * @returns Whether the version satisfied the version range.\n */\nexport function satisfiesVersionRange(\n version: SemVerVersion,\n versionRange: SemVerRange,\n): boolean {\n return satisfiesSemver(version, versionRange, {\n includePrerelease: true,\n });\n}\n"],"mappings":";;;;;AAAA;AAAA,EACE,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,SAAS;AAAA,EACT,cAAc;AAAA,OACT;AAEP,SAAS,IAAI,QAAQ,cAAc;AAoD5B,IAAM,gBAAgB;AAAA,EAC3B,OAAO;AAAA,EACP;AAAA,EACA,CAAC,UAAU;AACT,QAAI,mBAAmB,KAAK,MAAM,MAAM;AACtC,aAAO,iCAAiC,KAAK;AAAA,IAC/C;AACA,WAAO;AAAA,EACT;AACF;AAEO,IAAM,qBAAqB;AAAA,EAChC,OAAO;AAAA,EACP;AAAA,EACA,CAAC,UAAU;AACT,QAAI,iBAAiB,KAAK,MAAM,MAAM;AACpC,aAAO,+BAA+B,KAAK;AAAA,IAC7C;AACA,WAAO;AAAA,EACT;AACF;AAQO,SAAS,qBACd,SAC0B;AAC1B,SAAO,GAAG,SAAS,aAAa;AAClC;AAQO,SAAS,mBACd,cAC6B;AAC7B,SAAO,GAAG,cAAc,kBAAkB;AAC5C;AAOO,SAAS,sBACd,SACkC;AAClC,eAAa,SAAS,aAAa;AACrC;AAOO,SAAS,oBACd,OAC8B;AAC9B,eAAa,OAAO,kBAAkB;AACxC;AASO,SAAS,UACd,UACA,UACS;AACT,SAAO,SAAS,UAAU,QAAQ;AACpC;AASO,SAAS,QAAQ,SAAwB,OAA6B;AAC3E,SAAO,UAAU,SAAS,KAAK;AACjC;AASO,SAAS,sBACd,SACA,cACS;AACT,SAAO,gBAAgB,SAAS,cAAc;AAAA,IAC5C,mBAAmB;AAAA,EACrB,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-RRYOWRCV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
add0x,
|
|
3
|
+
assertIsHexString
|
|
4
|
+
} from "./chunk-VA2DRBDE.mjs";
|
|
5
|
+
import {
|
|
6
|
+
assert
|
|
7
|
+
} from "./chunk-74DGVJVE.mjs";
|
|
8
|
+
|
|
9
|
+
// src/number.ts
|
|
10
|
+
var numberToHex = (value) => {
|
|
11
|
+
assert(typeof value === "number", "Value must be a number.");
|
|
12
|
+
assert(value >= 0, "Value must be a non-negative number.");
|
|
13
|
+
assert(
|
|
14
|
+
Number.isSafeInteger(value),
|
|
15
|
+
"Value is not a safe integer. Use `bigIntToHex` instead."
|
|
16
|
+
);
|
|
17
|
+
return add0x(value.toString(16));
|
|
18
|
+
};
|
|
19
|
+
var bigIntToHex = (value) => {
|
|
20
|
+
assert(typeof value === "bigint", "Value must be a bigint.");
|
|
21
|
+
assert(value >= 0, "Value must be a non-negative bigint.");
|
|
22
|
+
return add0x(value.toString(16));
|
|
23
|
+
};
|
|
24
|
+
var hexToNumber = (value) => {
|
|
25
|
+
assertIsHexString(value);
|
|
26
|
+
const numberValue = parseInt(value, 16);
|
|
27
|
+
assert(
|
|
28
|
+
Number.isSafeInteger(numberValue),
|
|
29
|
+
"Value is not a safe integer. Use `hexToBigInt` instead."
|
|
30
|
+
);
|
|
31
|
+
return numberValue;
|
|
32
|
+
};
|
|
33
|
+
var hexToBigInt = (value) => {
|
|
34
|
+
assertIsHexString(value);
|
|
35
|
+
return BigInt(add0x(value));
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
numberToHex,
|
|
40
|
+
bigIntToHex,
|
|
41
|
+
hexToNumber,
|
|
42
|
+
hexToBigInt
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=chunk-S3UHBN2Z.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/number.ts"],"sourcesContent":["import { assert } from './assert';\nimport { add0x, assertIsHexString } from './hex';\n\n/**\n * Convert a number to a hexadecimal string. This verifies that the number is a\n * non-negative safe integer.\n *\n * To convert a `bigint` to a hexadecimal string instead, use\n * {@link bigIntToHex}.\n *\n * @example\n * ```typescript\n * numberToHex(0); // '0x0'\n * numberToHex(1); // '0x1'\n * numberToHex(16); // '0x10'\n * ```\n * @param value - The number to convert to a hexadecimal string.\n * @returns The hexadecimal string, with the \"0x\"-prefix.\n * @throws If the number is not a non-negative safe integer.\n */\nexport const numberToHex = (value: number): string => {\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 `bigIntToHex` instead.',\n );\n\n return add0x(value.toString(16));\n};\n\n/**\n * Convert a `bigint` to a hexadecimal string. This verifies that the `bigint`\n * is a non-negative integer.\n *\n * To convert a number to a hexadecimal string instead, use {@link numberToHex}.\n *\n * @example\n * ```typescript\n * bigIntToHex(0n); // '0x0'\n * bigIntToHex(1n); // '0x1'\n * bigIntToHex(16n); // '0x10'\n * ```\n * @param value - The `bigint` to convert to a hexadecimal string.\n * @returns The hexadecimal string, with the \"0x\"-prefix.\n * @throws If the `bigint` is not a non-negative integer.\n */\nexport const bigIntToHex = (value: bigint): string => {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= 0, 'Value must be a non-negative bigint.');\n\n return add0x(value.toString(16));\n};\n\n/**\n * Convert a hexadecimal string to a number. This verifies that the string is a\n * valid hex string, and that the resulting number is a safe integer. Both\n * \"0x\"-prefixed and unprefixed strings are supported.\n *\n * To convert a hexadecimal string to a `bigint` instead, use\n * {@link hexToBigInt}.\n *\n * @example\n * ```typescript\n * hexToNumber('0x0'); // 0\n * hexToNumber('0x1'); // 1\n * hexToNumber('0x10'); // 16\n * ```\n * @param value - The hexadecimal string to convert to a number.\n * @returns The number.\n * @throws If the value is not a valid hexadecimal string, or if the resulting\n * number is not a safe integer.\n */\nexport const hexToNumber = (value: string): number => {\n assertIsHexString(value);\n\n // `parseInt` accepts values without the \"0x\"-prefix, whereas `Number` does\n // not. Using this is slightly faster than `Number(add0x(value))`.\n const numberValue = parseInt(value, 16);\n\n assert(\n Number.isSafeInteger(numberValue),\n 'Value is not a safe integer. Use `hexToBigInt` instead.',\n );\n\n return numberValue;\n};\n\n/**\n * Convert a hexadecimal string to a `bigint`. This verifies that the string is\n * a valid hex string. Both \"0x\"-prefixed and unprefixed strings are supported.\n *\n * To convert a hexadecimal string to a number instead, use {@link hexToNumber}.\n *\n * @example\n * ```typescript\n * hexToBigInt('0x0'); // 0n\n * hexToBigInt('0x1'); // 1n\n * hexToBigInt('0x10'); // 16n\n * ```\n * @param value - The hexadecimal string to convert to a `bigint`.\n * @returns The `bigint`.\n * @throws If the value is not a valid hexadecimal string.\n */\nexport const hexToBigInt = (value: string): bigint => {\n assertIsHexString(value);\n\n // The `BigInt` constructor requires the \"0x\"-prefix to parse a hex string.\n return BigInt(add0x(value));\n};\n"],"mappings":";;;;;;;;;AAoBO,IAAM,cAAc,CAAC,UAA0B;AACpD,SAAO,OAAO,UAAU,UAAU,yBAAyB;AAC3D,SAAO,SAAS,GAAG,sCAAsC;AACzD;AAAA,IACE,OAAO,cAAc,KAAK;AAAA,IAC1B;AAAA,EACF;AAEA,SAAO,MAAM,MAAM,SAAS,EAAE,CAAC;AACjC;AAkBO,IAAM,cAAc,CAAC,UAA0B;AACpD,SAAO,OAAO,UAAU,UAAU,yBAAyB;AAC3D,SAAO,SAAS,GAAG,sCAAsC;AAEzD,SAAO,MAAM,MAAM,SAAS,EAAE,CAAC;AACjC;AAqBO,IAAM,cAAc,CAAC,UAA0B;AACpD,oBAAkB,KAAK;AAIvB,QAAM,cAAc,SAAS,OAAO,EAAE;AAEtC;AAAA,IACE,OAAO,cAAc,WAAW;AAAA,IAChC;AAAA,EACF;AAEA,SAAO;AACT;AAkBO,IAAM,cAAc,CAAC,UAA0B;AACpD,oBAAkB,KAAK;AAGvB,SAAO,OAAO,MAAM,KAAK,CAAC;AAC5B;","names":[]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/caip-types.ts
|
|
2
|
+
import { is, pattern, string } from "superstruct";
|
|
3
|
+
var CAIP_CHAIN_ID_REGEX = /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;
|
|
4
|
+
var CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;
|
|
5
|
+
var CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;
|
|
6
|
+
var CAIP_ACCOUNT_ID_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})):(?<accountAddress>[-.%a-zA-Z0-9]{1,128})$/u;
|
|
7
|
+
var CAIP_ACCOUNT_ADDRESS_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;
|
|
8
|
+
var CaipChainIdStruct = pattern(string(), CAIP_CHAIN_ID_REGEX);
|
|
9
|
+
var CaipNamespaceStruct = pattern(string(), CAIP_NAMESPACE_REGEX);
|
|
10
|
+
var CaipReferenceStruct = pattern(string(), CAIP_REFERENCE_REGEX);
|
|
11
|
+
var CaipAccountIdStruct = pattern(string(), CAIP_ACCOUNT_ID_REGEX);
|
|
12
|
+
var CaipAccountAddressStruct = pattern(
|
|
13
|
+
string(),
|
|
14
|
+
CAIP_ACCOUNT_ADDRESS_REGEX
|
|
15
|
+
);
|
|
16
|
+
function isCaipChainId(value) {
|
|
17
|
+
return is(value, CaipChainIdStruct);
|
|
18
|
+
}
|
|
19
|
+
function isCaipNamespace(value) {
|
|
20
|
+
return is(value, CaipNamespaceStruct);
|
|
21
|
+
}
|
|
22
|
+
function isCaipReference(value) {
|
|
23
|
+
return is(value, CaipReferenceStruct);
|
|
24
|
+
}
|
|
25
|
+
function isCaipAccountId(value) {
|
|
26
|
+
return is(value, CaipAccountIdStruct);
|
|
27
|
+
}
|
|
28
|
+
function isCaipAccountAddress(value) {
|
|
29
|
+
return is(value, CaipAccountAddressStruct);
|
|
30
|
+
}
|
|
31
|
+
function parseCaipChainId(caipChainId) {
|
|
32
|
+
const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);
|
|
33
|
+
if (!match?.groups) {
|
|
34
|
+
throw new Error("Invalid CAIP chain ID.");
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
namespace: match.groups.namespace,
|
|
38
|
+
reference: match.groups.reference
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function parseCaipAccountId(caipAccountId) {
|
|
42
|
+
const match = CAIP_ACCOUNT_ID_REGEX.exec(caipAccountId);
|
|
43
|
+
if (!match?.groups) {
|
|
44
|
+
throw new Error("Invalid CAIP account ID.");
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
address: match.groups.accountAddress,
|
|
48
|
+
chainId: match.groups.chainId,
|
|
49
|
+
chain: {
|
|
50
|
+
namespace: match.groups.namespace,
|
|
51
|
+
reference: match.groups.reference
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
CAIP_CHAIN_ID_REGEX,
|
|
58
|
+
CAIP_NAMESPACE_REGEX,
|
|
59
|
+
CAIP_REFERENCE_REGEX,
|
|
60
|
+
CAIP_ACCOUNT_ID_REGEX,
|
|
61
|
+
CAIP_ACCOUNT_ADDRESS_REGEX,
|
|
62
|
+
CaipChainIdStruct,
|
|
63
|
+
CaipNamespaceStruct,
|
|
64
|
+
CaipReferenceStruct,
|
|
65
|
+
CaipAccountIdStruct,
|
|
66
|
+
CaipAccountAddressStruct,
|
|
67
|
+
isCaipChainId,
|
|
68
|
+
isCaipNamespace,
|
|
69
|
+
isCaipReference,
|
|
70
|
+
isCaipAccountId,
|
|
71
|
+
isCaipAccountAddress,
|
|
72
|
+
parseCaipChainId,
|
|
73
|
+
parseCaipAccountId
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=chunk-TGOMTREC.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/caip-types.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport { is, pattern, string } 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\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const CaipChainIdStruct = pattern(string(), CAIP_CHAIN_ID_REGEX);\nexport type CaipChainId = `${string}:${string}`;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.\n */\nexport const CaipNamespaceStruct = pattern(string(), CAIP_NAMESPACE_REGEX);\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 = pattern(string(), CAIP_REFERENCE_REGEX);\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 = pattern(string(), CAIP_ACCOUNT_ID_REGEX);\nexport type CaipAccountId = `${string}:${string}:${string}`;\n\n/**\n * A CAIP-10 account address, i.e., the third part of the CAIP account ID.\n */\nexport const CaipAccountAddressStruct = pattern(\n string(),\n CAIP_ACCOUNT_ADDRESS_REGEX,\n);\nexport type CaipAccountAddress = Infer<typeof CaipAccountAddressStruct>;\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 * 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"],"mappings":";AACA,SAAS,IAAI,SAAS,cAAc;AAE7B,IAAM,sBACX;AAEK,IAAM,uBAAuB;AAE7B,IAAM,uBAAuB;AAE7B,IAAM,wBACX;AAEK,IAAM,6BAA6B;AAKnC,IAAM,oBAAoB,QAAQ,OAAO,GAAG,mBAAmB;AAM/D,IAAM,sBAAsB,QAAQ,OAAO,GAAG,oBAAoB;AAMlE,IAAM,sBAAsB,QAAQ,OAAO,GAAG,oBAAoB;AAMlE,IAAM,sBAAsB,QAAQ,OAAO,GAAG,qBAAqB;AAMnE,IAAM,2BAA2B;AAAA,EACtC,OAAO;AAAA,EACP;AACF;AASO,SAAS,cAAc,OAAsC;AAClE,SAAO,GAAG,OAAO,iBAAiB;AACpC;AAQO,SAAS,gBAAgB,OAAwC;AACtE,SAAO,GAAG,OAAO,mBAAmB;AACtC;AAQO,SAAS,gBAAgB,OAAwC;AACtE,SAAO,GAAG,OAAO,mBAAmB;AACtC;AAQO,SAAS,gBAAgB,OAAwC;AACtE,SAAO,GAAG,OAAO,mBAAmB;AACtC;AAQO,SAAS,qBACd,OAC6B;AAC7B,SAAO,GAAG,OAAO,wBAAwB;AAC3C;AASO,SAAS,iBAAiB,aAG/B;AACA,QAAM,QAAQ,oBAAoB,KAAK,WAAW;AAClD,MAAI,CAAC,OAAO,QAAQ;AAClB,UAAM,IAAI,MAAM,wBAAwB;AAAA,EAC1C;AAEA,SAAO;AAAA,IACL,WAAW,MAAM,OAAO;AAAA,IACxB,WAAW,MAAM,OAAO;AAAA,EAC1B;AACF;AASO,SAAS,mBAAmB,eAIjC;AACA,QAAM,QAAQ,sBAAsB,KAAK,aAAa;AACtD,MAAI,CAAC,OAAO,QAAQ;AAClB,UAAM,IAAI,MAAM,0BAA0B;AAAA,EAC5C;AAEA,SAAO;AAAA,IACL,SAAS,MAAM,OAAO;AAAA,IACtB,SAAS,MAAM,OAAO;AAAA,IACtB,OAAO;AAAA,MACL,WAAW,MAAM,OAAO;AAAA,MACxB,WAAW,MAAM,OAAO;AAAA,IAC1B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/time.ts
|
|
2
|
+
var Duration = /* @__PURE__ */ ((Duration2) => {
|
|
3
|
+
Duration2[Duration2["Millisecond"] = 1] = "Millisecond";
|
|
4
|
+
Duration2[Duration2["Second"] = 1e3] = "Second";
|
|
5
|
+
Duration2[Duration2["Minute"] = 6e4] = "Minute";
|
|
6
|
+
Duration2[Duration2["Hour"] = 36e5] = "Hour";
|
|
7
|
+
Duration2[Duration2["Day"] = 864e5] = "Day";
|
|
8
|
+
Duration2[Duration2["Week"] = 6048e5] = "Week";
|
|
9
|
+
Duration2[Duration2["Year"] = 31536e6] = "Year";
|
|
10
|
+
return Duration2;
|
|
11
|
+
})(Duration || {});
|
|
12
|
+
var isNonNegativeInteger = (number) => Number.isInteger(number) && number >= 0;
|
|
13
|
+
var assertIsNonNegativeInteger = (number, name) => {
|
|
14
|
+
if (!isNonNegativeInteger(number)) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
`"${name}" must be a non-negative integer. Received: "${number}".`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function inMilliseconds(count, duration) {
|
|
21
|
+
assertIsNonNegativeInteger(count, "count");
|
|
22
|
+
return count * duration;
|
|
23
|
+
}
|
|
24
|
+
function timeSince(timestamp) {
|
|
25
|
+
assertIsNonNegativeInteger(timestamp, "timestamp");
|
|
26
|
+
return Date.now() - timestamp;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
Duration,
|
|
31
|
+
inMilliseconds,
|
|
32
|
+
timeSince
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=chunk-THNLGEXV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/time.ts"],"sourcesContent":["/**\n * Common duration constants, in milliseconds.\n */\nexport enum Duration {\n /**\n * A millisecond.\n */\n Millisecond = 1,\n\n /**\n * A second, in milliseconds.\n */\n Second = 1000, // Millisecond * 1000\n\n /**\n * A minute, in milliseconds.\n */\n Minute = 60_000, // Second * 60\n\n /**\n * An hour, in milliseconds.\n */\n Hour = 3_600_000, // Minute * 60\n\n /**\n * A day, in milliseconds.\n */\n Day = 86_400_000, // Hour * 24\n\n /**\n * A week, in milliseconds.\n */\n Week = 604_800_000, // Day * 7\n\n /**\n * A year, in milliseconds.\n */\n Year = 31_536_000_000, // Day * 365\n}\n\nconst isNonNegativeInteger = (number: number) =>\n Number.isInteger(number) && number >= 0;\n\nconst assertIsNonNegativeInteger = (number: number, name: string) => {\n if (!isNonNegativeInteger(number)) {\n throw new Error(\n `\"${name}\" must be a non-negative integer. Received: \"${number}\".`,\n );\n }\n};\n\n/**\n * Calculates the millisecond value of the specified number of units of time.\n *\n * @param count - The number of units of time.\n * @param duration - The unit of time to count.\n * @returns The count multiplied by the specified duration.\n */\nexport function inMilliseconds(count: number, duration: Duration): number {\n assertIsNonNegativeInteger(count, 'count');\n return count * duration;\n}\n\n/**\n * Gets the milliseconds since a particular Unix epoch timestamp.\n *\n * @param timestamp - A Unix millisecond timestamp.\n * @returns The number of milliseconds elapsed since the specified timestamp.\n */\nexport function timeSince(timestamp: number): number {\n assertIsNonNegativeInteger(timestamp, 'timestamp');\n return Date.now() - timestamp;\n}\n"],"mappings":";AAGO,IAAK,WAAL,kBAAKA,cAAL;AAIL,EAAAA,oBAAA,iBAAc,KAAd;AAKA,EAAAA,oBAAA,YAAS,OAAT;AAKA,EAAAA,oBAAA,YAAS,OAAT;AAKA,EAAAA,oBAAA,UAAO,QAAP;AAKA,EAAAA,oBAAA,SAAM,SAAN;AAKA,EAAAA,oBAAA,UAAO,UAAP;AAKA,EAAAA,oBAAA,UAAO,WAAP;AAlCU,SAAAA;AAAA,GAAA;AAqCZ,IAAM,uBAAuB,CAAC,WAC5B,OAAO,UAAU,MAAM,KAAK,UAAU;AAExC,IAAM,6BAA6B,CAAC,QAAgB,SAAiB;AACnE,MAAI,CAAC,qBAAqB,MAAM,GAAG;AACjC,UAAM,IAAI;AAAA,MACR,IAAI,IAAI,gDAAgD,MAAM;AAAA,IAChE;AAAA,EACF;AACF;AASO,SAAS,eAAe,OAAe,UAA4B;AACxE,6BAA2B,OAAO,OAAO;AACzC,SAAO,QAAQ;AACjB;AAQO,SAAS,UAAU,WAA2B;AACnD,6BAA2B,WAAW,WAAW;AACjD,SAAO,KAAK,IAAI,IAAI;AACtB;","names":["Duration"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/caip-types.ts
|
|
2
|
+
var _superstruct = require('superstruct');
|
|
3
|
+
var CAIP_CHAIN_ID_REGEX = /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;
|
|
4
|
+
var CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;
|
|
5
|
+
var CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;
|
|
6
|
+
var CAIP_ACCOUNT_ID_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})):(?<accountAddress>[-.%a-zA-Z0-9]{1,128})$/u;
|
|
7
|
+
var CAIP_ACCOUNT_ADDRESS_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;
|
|
8
|
+
var CaipChainIdStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), CAIP_CHAIN_ID_REGEX);
|
|
9
|
+
var CaipNamespaceStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), CAIP_NAMESPACE_REGEX);
|
|
10
|
+
var CaipReferenceStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), CAIP_REFERENCE_REGEX);
|
|
11
|
+
var CaipAccountIdStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), CAIP_ACCOUNT_ID_REGEX);
|
|
12
|
+
var CaipAccountAddressStruct = _superstruct.pattern.call(void 0,
|
|
13
|
+
_superstruct.string.call(void 0, ),
|
|
14
|
+
CAIP_ACCOUNT_ADDRESS_REGEX
|
|
15
|
+
);
|
|
16
|
+
function isCaipChainId(value) {
|
|
17
|
+
return _superstruct.is.call(void 0, value, CaipChainIdStruct);
|
|
18
|
+
}
|
|
19
|
+
function isCaipNamespace(value) {
|
|
20
|
+
return _superstruct.is.call(void 0, value, CaipNamespaceStruct);
|
|
21
|
+
}
|
|
22
|
+
function isCaipReference(value) {
|
|
23
|
+
return _superstruct.is.call(void 0, value, CaipReferenceStruct);
|
|
24
|
+
}
|
|
25
|
+
function isCaipAccountId(value) {
|
|
26
|
+
return _superstruct.is.call(void 0, value, CaipAccountIdStruct);
|
|
27
|
+
}
|
|
28
|
+
function isCaipAccountAddress(value) {
|
|
29
|
+
return _superstruct.is.call(void 0, value, CaipAccountAddressStruct);
|
|
30
|
+
}
|
|
31
|
+
function parseCaipChainId(caipChainId) {
|
|
32
|
+
const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);
|
|
33
|
+
if (!_optionalChain([match, 'optionalAccess', _ => _.groups])) {
|
|
34
|
+
throw new Error("Invalid CAIP chain ID.");
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
namespace: match.groups.namespace,
|
|
38
|
+
reference: match.groups.reference
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function parseCaipAccountId(caipAccountId) {
|
|
42
|
+
const match = CAIP_ACCOUNT_ID_REGEX.exec(caipAccountId);
|
|
43
|
+
if (!_optionalChain([match, 'optionalAccess', _2 => _2.groups])) {
|
|
44
|
+
throw new Error("Invalid CAIP account ID.");
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
address: match.groups.accountAddress,
|
|
48
|
+
chainId: match.groups.chainId,
|
|
49
|
+
chain: {
|
|
50
|
+
namespace: match.groups.namespace,
|
|
51
|
+
reference: match.groups.reference
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
exports.CAIP_CHAIN_ID_REGEX = CAIP_CHAIN_ID_REGEX; exports.CAIP_NAMESPACE_REGEX = CAIP_NAMESPACE_REGEX; exports.CAIP_REFERENCE_REGEX = CAIP_REFERENCE_REGEX; exports.CAIP_ACCOUNT_ID_REGEX = CAIP_ACCOUNT_ID_REGEX; exports.CAIP_ACCOUNT_ADDRESS_REGEX = CAIP_ACCOUNT_ADDRESS_REGEX; exports.CaipChainIdStruct = CaipChainIdStruct; exports.CaipNamespaceStruct = CaipNamespaceStruct; exports.CaipReferenceStruct = CaipReferenceStruct; exports.CaipAccountIdStruct = CaipAccountIdStruct; exports.CaipAccountAddressStruct = CaipAccountAddressStruct; exports.isCaipChainId = isCaipChainId; exports.isCaipNamespace = isCaipNamespace; exports.isCaipReference = isCaipReference; exports.isCaipAccountId = isCaipAccountId; exports.isCaipAccountAddress = isCaipAccountAddress; exports.parseCaipChainId = parseCaipChainId; exports.parseCaipAccountId = parseCaipAccountId;
|
|
75
|
+
//# sourceMappingURL=chunk-U7ZUGCE7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/caip-types.ts"],"names":[],"mappings":";AACA,SAAS,IAAI,SAAS,cAAc;AAE7B,IAAM,sBACX;AAEK,IAAM,uBAAuB;AAE7B,IAAM,uBAAuB;AAE7B,IAAM,wBACX;AAEK,IAAM,6BAA6B;AAKnC,IAAM,oBAAoB,QAAQ,OAAO,GAAG,mBAAmB;AAM/D,IAAM,sBAAsB,QAAQ,OAAO,GAAG,oBAAoB;AAMlE,IAAM,sBAAsB,QAAQ,OAAO,GAAG,oBAAoB;AAMlE,IAAM,sBAAsB,QAAQ,OAAO,GAAG,qBAAqB;AAMnE,IAAM,2BAA2B;AAAA,EACtC,OAAO;AAAA,EACP;AACF;AASO,SAAS,cAAc,OAAsC;AAClE,SAAO,GAAG,OAAO,iBAAiB;AACpC;AAQO,SAAS,gBAAgB,OAAwC;AACtE,SAAO,GAAG,OAAO,mBAAmB;AACtC;AAQO,SAAS,gBAAgB,OAAwC;AACtE,SAAO,GAAG,OAAO,mBAAmB;AACtC;AAQO,SAAS,gBAAgB,OAAwC;AACtE,SAAO,GAAG,OAAO,mBAAmB;AACtC;AAQO,SAAS,qBACd,OAC6B;AAC7B,SAAO,GAAG,OAAO,wBAAwB;AAC3C;AASO,SAAS,iBAAiB,aAG/B;AACA,QAAM,QAAQ,oBAAoB,KAAK,WAAW;AAClD,MAAI,CAAC,OAAO,QAAQ;AAClB,UAAM,IAAI,MAAM,wBAAwB;AAAA,EAC1C;AAEA,SAAO;AAAA,IACL,WAAW,MAAM,OAAO;AAAA,IACxB,WAAW,MAAM,OAAO;AAAA,EAC1B;AACF;AASO,SAAS,mBAAmB,eAIjC;AACA,QAAM,QAAQ,sBAAsB,KAAK,aAAa;AACtD,MAAI,CAAC,OAAO,QAAQ;AAClB,UAAM,IAAI,MAAM,0BAA0B;AAAA,EAC5C;AAEA,SAAO;AAAA,IACL,SAAS,MAAM,OAAO;AAAA,IACtB,SAAS,MAAM,OAAO;AAAA,IACtB,OAAO;AAAA,MACL,WAAW,MAAM,OAAO;AAAA,MACxB,WAAW,MAAM,OAAO;AAAA,IAC1B;AAAA,EACF;AACF","sourcesContent":["import type { Infer } from 'superstruct';\nimport { is, pattern, string } 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\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const CaipChainIdStruct = pattern(string(), CAIP_CHAIN_ID_REGEX);\nexport type CaipChainId = `${string}:${string}`;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.\n */\nexport const CaipNamespaceStruct = pattern(string(), CAIP_NAMESPACE_REGEX);\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 = pattern(string(), CAIP_REFERENCE_REGEX);\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 = pattern(string(), CAIP_ACCOUNT_ID_REGEX);\nexport type CaipAccountId = `${string}:${string}:${string}`;\n\n/**\n * A CAIP-10 account address, i.e., the third part of the CAIP account ID.\n */\nexport const CaipAccountAddressStruct = pattern(\n string(),\n CAIP_ACCOUNT_ADDRESS_REGEX,\n);\nexport type CaipAccountAddress = Infer<typeof CaipAccountAddressStruct>;\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 * 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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";//# sourceMappingURL=chunk-UOTVU7OQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|