@solana/keys 2.0.0-experimental.caf8d51 → 2.0.0-experimental.cb1a5a0
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/README.md +4 -0
- package/dist/index.browser.cjs +80 -7
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +78 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +321 -162
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +68 -4
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +70 -7
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +68 -4
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +5 -2
- package/dist/types/base58.d.ts +5 -0
- package/dist/types/guard.d.ts +5 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/key-pair.d.ts +2 -0
- package/package.json +15 -12
package/dist/index.native.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { base58, string } from '@metaplex-foundation/umi-serializers';
|
|
2
2
|
|
|
3
|
-
//
|
|
3
|
+
// ../build-scripts/env-shim.ts
|
|
4
|
+
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
4
5
|
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
5
6
|
try {
|
|
6
7
|
if (
|
|
@@ -10,7 +11,7 @@ function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
|
10
11
|
) {
|
|
11
12
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
12
13
|
}
|
|
13
|
-
const bytes =
|
|
14
|
+
const bytes = base58.serialize(putativeBase58EncodedAddress);
|
|
14
15
|
const numBytes = bytes.byteLength;
|
|
15
16
|
if (numBytes !== 32) {
|
|
16
17
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
@@ -21,7 +22,70 @@ function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
function getBase58EncodedAddressCodec(config) {
|
|
26
|
+
return string({
|
|
27
|
+
description: config?.description ?? (__DEV__ ? "A 32-byte account address" : ""),
|
|
28
|
+
encoding: base58,
|
|
29
|
+
size: 32
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function getBase58EncodedAddressComparator() {
|
|
33
|
+
return new Intl.Collator("en", {
|
|
34
|
+
caseFirst: "lower",
|
|
35
|
+
ignorePunctuation: false,
|
|
36
|
+
localeMatcher: "best fit",
|
|
37
|
+
numeric: false,
|
|
38
|
+
sensitivity: "variant",
|
|
39
|
+
usage: "sort"
|
|
40
|
+
}).compare;
|
|
41
|
+
}
|
|
42
|
+
var cachedEd25519Decision;
|
|
43
|
+
async function isEd25519CurveSupported(subtle) {
|
|
44
|
+
if (cachedEd25519Decision === void 0) {
|
|
45
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
46
|
+
subtle.generateKey(
|
|
47
|
+
"Ed25519",
|
|
48
|
+
/* extractable */
|
|
49
|
+
false,
|
|
50
|
+
["sign", "verify"]
|
|
51
|
+
).catch(() => {
|
|
52
|
+
resolve(cachedEd25519Decision = false);
|
|
53
|
+
}).then(() => {
|
|
54
|
+
resolve(cachedEd25519Decision = true);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
59
|
+
return cachedEd25519Decision;
|
|
60
|
+
} else {
|
|
61
|
+
return await cachedEd25519Decision;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function assertKeyGenerationIsAvailable() {
|
|
65
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
66
|
+
throw new Error("No key generation implementation could be found");
|
|
67
|
+
}
|
|
68
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
69
|
+
throw new Error("This runtime does not support the generation of Ed25519 keypairs");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/key-pair.ts
|
|
74
|
+
async function generateKeyPair() {
|
|
75
|
+
await assertKeyGenerationIsAvailable();
|
|
76
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
77
|
+
/* algorithm */
|
|
78
|
+
"Ed25519",
|
|
79
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
80
|
+
/* extractable */
|
|
81
|
+
false,
|
|
82
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
83
|
+
/* allowed uses */
|
|
84
|
+
["sign", "verify"]
|
|
85
|
+
);
|
|
86
|
+
return keyPair;
|
|
87
|
+
}
|
|
24
88
|
|
|
25
|
-
export { assertIsBase58EncodedAddress };
|
|
89
|
+
export { assertIsBase58EncodedAddress, generateKeyPair, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator };
|
|
26
90
|
//# sourceMappingURL=out.js.map
|
|
27
91
|
//# sourceMappingURL=index.native.js.map
|
package/dist/index.native.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/base58.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../build-scripts/env-shim.ts","../src/base58.ts","../src/guard.ts","../src/key-pair.ts"],"names":[],"mappings":";AACO,IAAM,UAA2B,uBAAO,QAAgB,KAAU,EAAE,aAAa,eAAe;;;ACDvG,SAAS,QAAoB,cAAc;AAMpC,SAAS,6BACZ,8BACiG;AACjG,MAAI;AAEA;AAAA;AAAA,MAEI,6BAA6B,SAAS;AAAA,MAEtC,6BAA6B,SAAS;AAAA,MACxC;AACE,YAAM,IAAI,MAAM,+DAA+D;AAAA,IACnF;AAEA,UAAM,QAAQ,OAAO,UAAU,4BAA4B;AAC3D,UAAM,WAAW,MAAM;AACvB,QAAI,aAAa,IAAI;AACjB,YAAM,IAAI,MAAM,gFAAgF,UAAU;AA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AM,IAAI,MAAM,kEAAkE;AAAA,EACtF;AACJ;;;ACvCA,eAAsB,kBAA0C;AAC5D,QAAM,+BAA+B;AACrC,QAAM,UAAU,MAAM,OAAO,OAAO;AAAA;AAAA,IAChB;AAAA;AAAA;AAAA,IACE;AAAA;AAAA;AAAA,IACC,CAAC,QAAQ,QAAQ;AAAA,EACxC;AACA,SAAO;AACX","sourcesContent":["// Clever obfuscation to prevent the build system from inlining the value of `NODE_ENV`\nexport const __DEV__ = /* @__PURE__ */ (() => (process as any)['en' + 'v'].NODE_ENV === 'development')();\n","import { base58, Serializer, string } from '@metaplex-foundation/umi-serializers';\n\nexport type Base58EncodedAddress<TAddress extends string = string> = TAddress & {\n readonly __base58EncodedAddress: unique symbol;\n};\n\nexport function assertIsBase58EncodedAddress(\n putativeBase58EncodedAddress: string\n): asserts putativeBase58EncodedAddress is Base58EncodedAddress<typeof putativeBase58EncodedAddress> {\n try {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest address (32 bytes of zeroes)\n putativeBase58EncodedAddress.length < 32 ||\n // Highest address (32 bytes of 255)\n putativeBase58EncodedAddress.length > 44\n ) {\n throw new Error('Expected input string to decode to a byte array of length 32.');\n }\n // Slow-path; actually attempt to decode the input string.\n const bytes = base58.serialize(putativeBase58EncodedAddress);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);\n }\n } catch (e) {\n throw new Error(`\\`${putativeBase58EncodedAddress}\\` is not a base-58 encoded address`, {\n cause: e,\n });\n }\n}\n\nexport function getBase58EncodedAddressCodec(\n config?: Readonly<{\n description: string;\n }>\n): Serializer<Base58EncodedAddress> {\n return string({\n description: config?.description ?? (__DEV__ ? 'A 32-byte account address' : ''),\n encoding: base58,\n size: 32,\n }) as unknown as Serializer<Base58EncodedAddress>;\n}\n\nexport function getBase58EncodedAddressComparator(): (x: string, y: string) => number {\n return new Intl.Collator('en', {\n caseFirst: 'lower',\n ignorePunctuation: false,\n localeMatcher: 'best fit',\n numeric: false,\n sensitivity: 'variant',\n usage: 'sort',\n }).compare;\n}\n","function assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n // TODO: Coded error.\n throw new Error(\n 'Cryptographic operations are only allowed in secure browser contexts. Read more ' +\n 'here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts'\n );\n }\n}\n\nlet cachedEd25519Decision: PromiseLike<boolean> | boolean | undefined;\nasync function isEd25519CurveSupported(subtle: SubtleCrypto): Promise<boolean> {\n if (cachedEd25519Decision === undefined) {\n cachedEd25519Decision = new Promise(resolve => {\n subtle\n .generateKey('Ed25519', /* extractable */ false, ['sign', 'verify'])\n .catch(() => {\n resolve((cachedEd25519Decision = false));\n })\n .then(() => {\n resolve((cachedEd25519Decision = true));\n });\n });\n }\n if (typeof cachedEd25519Decision === 'boolean') {\n return cachedEd25519Decision;\n } else {\n return await cachedEd25519Decision;\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key generation implementation could be found');\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n // TODO: Coded error.\n throw new Error('This runtime does not support the generation of Ed25519 keypairs');\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key export implementation could be found');\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n // TODO: Coded error.\n throw new Error('No signing implementation could be found');\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n // TODO: Coded error.\n throw new Error('No signature verification implementation could be found');\n }\n}\n","import { assertKeyGenerationIsAvailable } from './guard';\n\nexport async function generateKeyPair(): Promise<CryptoKeyPair> {\n await assertKeyGenerationIsAvailable();\n const keyPair = await crypto.subtle.generateKey(\n /* algorithm */ 'Ed25519', // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20\n /* extractable */ false, // Prevents the bytes of the private key from being visible to JS.\n /* allowed uses */ ['sign', 'verify']\n );\n return keyPair as CryptoKeyPair;\n}\n"]}
|
package/dist/index.node.cjs
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var umiSerializers = require('@metaplex-foundation/umi-serializers');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var bs58__default = /*#__PURE__*/_interopDefault(bs58);
|
|
8
|
-
|
|
9
|
-
// src/base58.ts
|
|
5
|
+
// ../build-scripts/env-shim.ts
|
|
6
|
+
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
10
7
|
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
11
8
|
try {
|
|
12
9
|
if (
|
|
@@ -16,7 +13,7 @@ function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
|
16
13
|
) {
|
|
17
14
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
18
15
|
}
|
|
19
|
-
const bytes =
|
|
16
|
+
const bytes = umiSerializers.base58.serialize(putativeBase58EncodedAddress);
|
|
20
17
|
const numBytes = bytes.byteLength;
|
|
21
18
|
if (numBytes !== 32) {
|
|
22
19
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
@@ -27,7 +24,73 @@ function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
|
27
24
|
});
|
|
28
25
|
}
|
|
29
26
|
}
|
|
27
|
+
function getBase58EncodedAddressCodec(config) {
|
|
28
|
+
return umiSerializers.string({
|
|
29
|
+
description: config?.description ?? (__DEV__ ? "A 32-byte account address" : ""),
|
|
30
|
+
encoding: umiSerializers.base58,
|
|
31
|
+
size: 32
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function getBase58EncodedAddressComparator() {
|
|
35
|
+
return new Intl.Collator("en", {
|
|
36
|
+
caseFirst: "lower",
|
|
37
|
+
ignorePunctuation: false,
|
|
38
|
+
localeMatcher: "best fit",
|
|
39
|
+
numeric: false,
|
|
40
|
+
sensitivity: "variant",
|
|
41
|
+
usage: "sort"
|
|
42
|
+
}).compare;
|
|
43
|
+
}
|
|
44
|
+
var cachedEd25519Decision;
|
|
45
|
+
async function isEd25519CurveSupported(subtle) {
|
|
46
|
+
if (cachedEd25519Decision === void 0) {
|
|
47
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
48
|
+
subtle.generateKey(
|
|
49
|
+
"Ed25519",
|
|
50
|
+
/* extractable */
|
|
51
|
+
false,
|
|
52
|
+
["sign", "verify"]
|
|
53
|
+
).catch(() => {
|
|
54
|
+
resolve(cachedEd25519Decision = false);
|
|
55
|
+
}).then(() => {
|
|
56
|
+
resolve(cachedEd25519Decision = true);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
61
|
+
return cachedEd25519Decision;
|
|
62
|
+
} else {
|
|
63
|
+
return await cachedEd25519Decision;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function assertKeyGenerationIsAvailable() {
|
|
67
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
68
|
+
throw new Error("No key generation implementation could be found");
|
|
69
|
+
}
|
|
70
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
71
|
+
throw new Error("This runtime does not support the generation of Ed25519 keypairs");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/key-pair.ts
|
|
76
|
+
async function generateKeyPair() {
|
|
77
|
+
await assertKeyGenerationIsAvailable();
|
|
78
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
79
|
+
/* algorithm */
|
|
80
|
+
"Ed25519",
|
|
81
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
82
|
+
/* extractable */
|
|
83
|
+
false,
|
|
84
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
85
|
+
/* allowed uses */
|
|
86
|
+
["sign", "verify"]
|
|
87
|
+
);
|
|
88
|
+
return keyPair;
|
|
89
|
+
}
|
|
30
90
|
|
|
31
91
|
exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
|
|
92
|
+
exports.generateKeyPair = generateKeyPair;
|
|
93
|
+
exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
|
|
94
|
+
exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
|
|
32
95
|
//# sourceMappingURL=out.js.map
|
|
33
96
|
//# sourceMappingURL=index.node.cjs.map
|
package/dist/index.node.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/base58.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../build-scripts/env-shim.ts","../src/base58.ts","../src/guard.ts","../src/key-pair.ts"],"names":[],"mappings":";AACO,IAAM,UAA2B,uBAAO,QAAgB,KAAU,EAAE,aAAa,eAAe;;;ACDvG,SAAS,QAAoB,cAAc;AAMpC,SAAS,6BACZ,8BACiG;AACjG,MAAI;AAEA;AAAA;AAAA,MAEI,6BAA6B,SAAS;AAAA,MAEtC,6BAA6B,SAAS;AAAA,MACxC;AACE,YAAM,IAAI,MAAM,+DAA+D;AAAA,IACnF;AAEA,UAAM,QAAQ,OAAO,UAAU,4BAA4B;AAC3D,UAAM,WAAW,MAAM;AACvB,QAAI,aAAa,IAAI;AACjB,YAAM,IAAI,M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MAAM,GAAI;AAE5D,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACtF;AACJ;;;ACvCA,eAAsB,kBAA0C;AAC5D,QAAM,+BAA+B;AACrC,QAAM,UAAU,MAAM,OAAO,OAAO;AAAA;AAAA,IAChB;AAAA;AAAA;AAAA,IACE;AAAA;AAAA;AAAA,IACC,CAAC,QAAQ,QAAQ;AAAA,EACxC;AACA,SAAO;AACX","sourcesContent":["// Clever obfuscation to prevent the build system from inlining the value of `NODE_ENV`\nexport const __DEV__ = /* @__PURE__ */ (() => (process as any)['en' + 'v'].NODE_ENV === 'development')();\n","import { base58, Serializer, string } from '@metaplex-foundation/umi-serializers';\n\nexport type Base58EncodedAddress<TAddress extends string = string> = TAddress & {\n readonly __base58EncodedAddress: unique symbol;\n};\n\nexport function assertIsBase58EncodedAddress(\n putativeBase58EncodedAddress: string\n): asserts putativeBase58EncodedAddress is Base58EncodedAddress<typeof putativeBase58EncodedAddress> {\n try {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest address (32 bytes of zeroes)\n putativeBase58EncodedAddress.length < 32 ||\n // Highest address (32 bytes of 255)\n putativeBase58EncodedAddress.length > 44\n ) {\n throw new Error('Expected input string to decode to a byte array of length 32.');\n }\n // Slow-path; actually attempt to decode the input string.\n const bytes = base58.serialize(putativeBase58EncodedAddress);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);\n }\n } catch (e) {\n throw new Error(`\\`${putativeBase58EncodedAddress}\\` is not a base-58 encoded address`, {\n cause: e,\n });\n }\n}\n\nexport function getBase58EncodedAddressCodec(\n config?: Readonly<{\n description: string;\n }>\n): Serializer<Base58EncodedAddress> {\n return string({\n description: config?.description ?? (__DEV__ ? 'A 32-byte account address' : ''),\n encoding: base58,\n size: 32,\n }) as unknown as Serializer<Base58EncodedAddress>;\n}\n\nexport function getBase58EncodedAddressComparator(): (x: string, y: string) => number {\n return new Intl.Collator('en', {\n caseFirst: 'lower',\n ignorePunctuation: false,\n localeMatcher: 'best fit',\n numeric: false,\n sensitivity: 'variant',\n usage: 'sort',\n }).compare;\n}\n","function assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n // TODO: Coded error.\n throw new Error(\n 'Cryptographic operations are only allowed in secure browser contexts. Read more ' +\n 'here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts'\n );\n }\n}\n\nlet cachedEd25519Decision: PromiseLike<boolean> | boolean | undefined;\nasync function isEd25519CurveSupported(subtle: SubtleCrypto): Promise<boolean> {\n if (cachedEd25519Decision === undefined) {\n cachedEd25519Decision = new Promise(resolve => {\n subtle\n .generateKey('Ed25519', /* extractable */ false, ['sign', 'verify'])\n .catch(() => {\n resolve((cachedEd25519Decision = false));\n })\n .then(() => {\n resolve((cachedEd25519Decision = true));\n });\n });\n }\n if (typeof cachedEd25519Decision === 'boolean') {\n return cachedEd25519Decision;\n } else {\n return await cachedEd25519Decision;\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key generation implementation could be found');\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n // TODO: Coded error.\n throw new Error('This runtime does not support the generation of Ed25519 keypairs');\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key export implementation could be found');\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n // TODO: Coded error.\n throw new Error('No signing implementation could be found');\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n // TODO: Coded error.\n throw new Error('No signature verification implementation could be found');\n }\n}\n","import { assertKeyGenerationIsAvailable } from './guard';\n\nexport async function generateKeyPair(): Promise<CryptoKeyPair> {\n await assertKeyGenerationIsAvailable();\n const keyPair = await crypto.subtle.generateKey(\n /* algorithm */ 'Ed25519', // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20\n /* extractable */ false, // Prevents the bytes of the private key from being visible to JS.\n /* allowed uses */ ['sign', 'verify']\n );\n return keyPair as CryptoKeyPair;\n}\n"]}
|
package/dist/index.node.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { base58, string } from '@metaplex-foundation/umi-serializers';
|
|
2
2
|
|
|
3
|
-
//
|
|
3
|
+
// ../build-scripts/env-shim.ts
|
|
4
|
+
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
4
5
|
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
5
6
|
try {
|
|
6
7
|
if (
|
|
@@ -10,7 +11,7 @@ function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
|
10
11
|
) {
|
|
11
12
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
12
13
|
}
|
|
13
|
-
const bytes =
|
|
14
|
+
const bytes = base58.serialize(putativeBase58EncodedAddress);
|
|
14
15
|
const numBytes = bytes.byteLength;
|
|
15
16
|
if (numBytes !== 32) {
|
|
16
17
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
@@ -21,7 +22,70 @@ function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
function getBase58EncodedAddressCodec(config) {
|
|
26
|
+
return string({
|
|
27
|
+
description: config?.description ?? (__DEV__ ? "A 32-byte account address" : ""),
|
|
28
|
+
encoding: base58,
|
|
29
|
+
size: 32
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function getBase58EncodedAddressComparator() {
|
|
33
|
+
return new Intl.Collator("en", {
|
|
34
|
+
caseFirst: "lower",
|
|
35
|
+
ignorePunctuation: false,
|
|
36
|
+
localeMatcher: "best fit",
|
|
37
|
+
numeric: false,
|
|
38
|
+
sensitivity: "variant",
|
|
39
|
+
usage: "sort"
|
|
40
|
+
}).compare;
|
|
41
|
+
}
|
|
42
|
+
var cachedEd25519Decision;
|
|
43
|
+
async function isEd25519CurveSupported(subtle) {
|
|
44
|
+
if (cachedEd25519Decision === void 0) {
|
|
45
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
46
|
+
subtle.generateKey(
|
|
47
|
+
"Ed25519",
|
|
48
|
+
/* extractable */
|
|
49
|
+
false,
|
|
50
|
+
["sign", "verify"]
|
|
51
|
+
).catch(() => {
|
|
52
|
+
resolve(cachedEd25519Decision = false);
|
|
53
|
+
}).then(() => {
|
|
54
|
+
resolve(cachedEd25519Decision = true);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
59
|
+
return cachedEd25519Decision;
|
|
60
|
+
} else {
|
|
61
|
+
return await cachedEd25519Decision;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function assertKeyGenerationIsAvailable() {
|
|
65
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
66
|
+
throw new Error("No key generation implementation could be found");
|
|
67
|
+
}
|
|
68
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
69
|
+
throw new Error("This runtime does not support the generation of Ed25519 keypairs");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/key-pair.ts
|
|
74
|
+
async function generateKeyPair() {
|
|
75
|
+
await assertKeyGenerationIsAvailable();
|
|
76
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
77
|
+
/* algorithm */
|
|
78
|
+
"Ed25519",
|
|
79
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
80
|
+
/* extractable */
|
|
81
|
+
false,
|
|
82
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
83
|
+
/* allowed uses */
|
|
84
|
+
["sign", "verify"]
|
|
85
|
+
);
|
|
86
|
+
return keyPair;
|
|
87
|
+
}
|
|
24
88
|
|
|
25
|
-
export { assertIsBase58EncodedAddress };
|
|
89
|
+
export { assertIsBase58EncodedAddress, generateKeyPair, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator };
|
|
26
90
|
//# sourceMappingURL=out.js.map
|
|
27
91
|
//# sourceMappingURL=index.node.js.map
|
package/dist/index.node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/base58.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../build-scripts/env-shim.ts","../src/base58.ts","../src/guard.ts","../src/key-pair.ts"],"names":[],"mappings":";AACO,IAAM,UAA2B,uBAAO,QAAgB,KAAU,EAAE,aAAa,eAAe;;;ACDvG,SAAS,QAAoB,cAAc;AAMpC,SAAS,6BACZ,8BACiG;AACjG,MAAI;AAEA;AAAA;AAAA,MAEI,6BAA6B,SAAS;AAAA,MAEtC,6BAA6B,SAAS;AAAA,MACxC;AACE,YAAM,IAAI,MAAM,+DAA+D;AAAA,IACnF;AAEA,UAAM,QAAQ,OAAO,UAAU,4BAA4B;AAC3D,UAAM,WAAW,MAAM;AACvB,QAAI,aAAa,IAAI;AACjB,YAAM,IAAI,MAAM,gFAAgF,UAAU;AAAA,IAC9G;AAAA,EACJ,SAAS,GAAP;AACE,UAAM,IAAI,MAAM,KAAK,mEAAmE;AAAA,MACpF,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,6BACZ,QAGgC;AAChC,SAAO,OAAO;AAAA,IACV,aAAa,QAAQ,gB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QAAQ,QAAQ;AAAA,EACxC;AACA,SAAO;AACX","sourcesContent":["// Clever obfuscation to prevent the build system from inlining the value of `NODE_ENV`\nexport const __DEV__ = /* @__PURE__ */ (() => (process as any)['en' + 'v'].NODE_ENV === 'development')();\n","import { base58, Serializer, string } from '@metaplex-foundation/umi-serializers';\n\nexport type Base58EncodedAddress<TAddress extends string = string> = TAddress & {\n readonly __base58EncodedAddress: unique symbol;\n};\n\nexport function assertIsBase58EncodedAddress(\n putativeBase58EncodedAddress: string\n): asserts putativeBase58EncodedAddress is Base58EncodedAddress<typeof putativeBase58EncodedAddress> {\n try {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest address (32 bytes of zeroes)\n putativeBase58EncodedAddress.length < 32 ||\n // Highest address (32 bytes of 255)\n putativeBase58EncodedAddress.length > 44\n ) {\n throw new Error('Expected input string to decode to a byte array of length 32.');\n }\n // Slow-path; actually attempt to decode the input string.\n const bytes = base58.serialize(putativeBase58EncodedAddress);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);\n }\n } catch (e) {\n throw new Error(`\\`${putativeBase58EncodedAddress}\\` is not a base-58 encoded address`, {\n cause: e,\n });\n }\n}\n\nexport function getBase58EncodedAddressCodec(\n config?: Readonly<{\n description: string;\n }>\n): Serializer<Base58EncodedAddress> {\n return string({\n description: config?.description ?? (__DEV__ ? 'A 32-byte account address' : ''),\n encoding: base58,\n size: 32,\n }) as unknown as Serializer<Base58EncodedAddress>;\n}\n\nexport function getBase58EncodedAddressComparator(): (x: string, y: string) => number {\n return new Intl.Collator('en', {\n caseFirst: 'lower',\n ignorePunctuation: false,\n localeMatcher: 'best fit',\n numeric: false,\n sensitivity: 'variant',\n usage: 'sort',\n }).compare;\n}\n","function assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n // TODO: Coded error.\n throw new Error(\n 'Cryptographic operations are only allowed in secure browser contexts. Read more ' +\n 'here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts'\n );\n }\n}\n\nlet cachedEd25519Decision: PromiseLike<boolean> | boolean | undefined;\nasync function isEd25519CurveSupported(subtle: SubtleCrypto): Promise<boolean> {\n if (cachedEd25519Decision === undefined) {\n cachedEd25519Decision = new Promise(resolve => {\n subtle\n .generateKey('Ed25519', /* extractable */ false, ['sign', 'verify'])\n .catch(() => {\n resolve((cachedEd25519Decision = false));\n })\n .then(() => {\n resolve((cachedEd25519Decision = true));\n });\n });\n }\n if (typeof cachedEd25519Decision === 'boolean') {\n return cachedEd25519Decision;\n } else {\n return await cachedEd25519Decision;\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key generation implementation could be found');\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n // TODO: Coded error.\n throw new Error('This runtime does not support the generation of Ed25519 keypairs');\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key export implementation could be found');\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n // TODO: Coded error.\n throw new Error('No signing implementation could be found');\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n // TODO: Coded error.\n throw new Error('No signature verification implementation could be found');\n }\n}\n","import { assertKeyGenerationIsAvailable } from './guard';\n\nexport async function generateKeyPair(): Promise<CryptoKeyPair> {\n await assertKeyGenerationIsAvailable();\n const keyPair = await crypto.subtle.generateKey(\n /* algorithm */ 'Ed25519', // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20\n /* extractable */ false, // Prevents the bytes of the private key from being visible to JS.\n /* allowed uses */ ['sign', 'verify']\n );\n return keyPair as CryptoKeyPair;\n}\n"]}
|
|
@@ -2,9 +2,12 @@ this.globalThis = this.globalThis || {};
|
|
|
2
2
|
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _=Object.defineProperty;var O=(e,r,t)=>r in e?_(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var u=(e,r,t)=>(O(e,typeof r!="symbol"?r+"":r,t),t);var w=e=>{let r=e.reduce((n,i)=>n+i.length,0),t=new Uint8Array(r),o=0;return e.forEach(n=>{t.set(n,o),o+=n.length;}),t},N=(e,r)=>{if(e.length>=r)return e;let t=new Uint8Array(r).fill(0);return t.set(e),t},y=(e,r)=>N(e.slice(0,r),r);var g=class extends Error{constructor(t){super(`Serializer [${t}] cannot deserialize empty buffers.`);u(this,"name","DeserializingEmptyBufferError");}},d=class extends Error{constructor(t,o,n){super(`Serializer [${t}] expected ${o} bytes, got ${n}.`);u(this,"name","NotEnoughBytesError");}};function S(e,r,t){return {description:t??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r,serialize:o=>y(e.serialize(o),r),deserialize:(o,n=0)=>{if(o=o.slice(n,n+r),o.length<r)throw new d("fixSerializer",r,o.length);e.fixedSize!==null&&(o=y(o,e.fixedSize));let[i]=e.deserialize(o,0);return [i,n+r]}}}var h=class extends Error{constructor(t,o,n){let i=`Expected a string of base ${o}, got [${t}].`;super(i);u(this,"name","InvalidBaseStringError");this.cause=n;}};var I=e=>{let r=e.length,t=BigInt(r);return {description:`base${r}`,fixedSize:null,maxSize:null,serialize(o){if(!o.match(new RegExp(`^[${e}]*$`)))throw new h(o,r);if(o==="")return new Uint8Array;let n=[...o],i=n.findIndex(f=>f!==e[0]);i=i===-1?n.length:i;let a=Array(i).fill(0);if(i===n.length)return Uint8Array.from(a);let m=n.slice(i),l=0n,c=1n;for(let f=m.length-1;f>=0;f-=1)l+=c*BigInt(e.indexOf(m[f])),c*=t;let p=[];for(;l>0n;)p.unshift(Number(l%256n)),l/=256n;return Uint8Array.from(a.concat(p))},deserialize(o,n=0){if(o.length===0)return ["",0];let i=o.slice(n),a=i.findIndex(p=>p!==0);a=a===-1?i.length:a;let m=e[0].repeat(a);if(a===i.length)return [m,o.length];let l=i.slice(a).reduce((p,f)=>p*256n+BigInt(f),0n),c=[];for(;l>0n;)c.unshift(e[Number(l%t)]),l/=t;return [m+c.join(""),o.length]}}};var E=I("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var C=e=>e.replace(/\u0000/g,"");var B={description:"utf8",fixedSize:null,maxSize:null,serialize(e){return new TextEncoder().encode(e)},deserialize(e,r=0){let t=new TextDecoder().decode(e.slice(r));return [C(t),e.length]}};var b;(function(e){e.Little="le",e.Big="be";})(b||(b={}));var z=class extends RangeError{constructor(t,o,n,i){super(`Serializer [${t}] expected number to be between ${o} and ${n}, got ${i}.`);u(this,"name","NumberOutOfRangeError");}};function $(e){let r,t=e.name;return e.size>1&&(r=!("endian"in e.options)||e.options.endian===b.Little,t+=r?"(le)":"(be)"),{description:e.options.description??t,fixedSize:e.size,maxSize:e.size,serialize(o){e.range&&P(e.name,e.range[0],e.range[1],o);let n=new ArrayBuffer(e.size);return e.set(new DataView(n),o,r),new Uint8Array(n)},deserialize(o,n=0){let i=o.slice(n,n+e.size);k("i8",i,e.size);let a=U(i);return [e.get(a,r),n+e.size]}}}var R=e=>e.buffer.slice(e.byteOffset,e.byteLength+e.byteOffset),U=e=>new DataView(R(e)),P=(e,r,t,o)=>{if(o<r||o>t)throw new z(e,r,t,o)},k=(e,r,t)=>{if(r.length===0)throw new g(e);if(r.length<t)throw new d(e,t,r.length)};var A=(e={})=>$({name:"u32",size:4,range:[0,+"0xffffffff"],set:(r,t,o)=>r.setUint32(0,Number(t),o),get:(r,t)=>r.getUint32(0,t),options:e});function D(e){return typeof e=="object"?e.description:`${e}`}function v(e={}){let r=e.size??A(),t=e.encoding??B,o=e.description??`string(${t.description}; ${D(r)})`;return r==="variable"?{...t,description:o}:typeof r=="number"?S(t,r,o):{description:o,fixedSize:null,maxSize:null,serialize:n=>{let i=t.serialize(n),a=r.serialize(i.length);return w([a,i])},deserialize:(n,i=0)=>{if(n.slice(i).length===0)throw new g("string");let[a,m]=r.deserialize(n,i),l=Number(a);i=m;let c=n.slice(i,i+l);if(c.length<l)throw new d("string",l,c.length);let[p,f]=t.deserialize(c);return i+=f,[p,i]}}}function er(e){try{if(e.length<32||e.length>44)throw new Error("Expected input string to decode to a byte array of length 32.");let t=E.serialize(e).byteLength;if(t!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${t}`)}catch(r){throw new Error(`\`${e}\` is not a base-58 encoded address`,{cause:r})}}function rr(e){return v({description:e?.description??"",encoding:E,size:32})}function tr(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}function K(){if(!globalThis.isSecureContext)throw new Error("Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts")}var x;async function L(e){return x===void 0&&(x=new Promise(r=>{e.generateKey("Ed25519",!1,["sign","verify"]).catch(()=>{r(x=!1);}).then(()=>{r(x=!0);});})),typeof x=="boolean"?x:await x}async function T(){if(K(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.generateKey!="function")throw new Error("No key generation implementation could be found");if(!await L(globalThis.crypto.subtle))throw new Error("This runtime does not support the generation of Ed25519 keypairs")}async function lr(){return await T(),await crypto.subtle.generateKey("Ed25519",!1,["sign","verify"])}
|
|
6
6
|
|
|
7
|
-
exports.assertIsBase58EncodedAddress =
|
|
7
|
+
exports.assertIsBase58EncodedAddress = er;
|
|
8
|
+
exports.generateKeyPair = lr;
|
|
9
|
+
exports.getBase58EncodedAddressCodec = rr;
|
|
10
|
+
exports.getBase58EncodedAddressComparator = tr;
|
|
8
11
|
|
|
9
12
|
return exports;
|
|
10
13
|
|
package/dist/types/base58.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { Serializer } from '@metaplex-foundation/umi-serializers';
|
|
1
2
|
export type Base58EncodedAddress<TAddress extends string = string> = TAddress & {
|
|
2
3
|
readonly __base58EncodedAddress: unique symbol;
|
|
3
4
|
};
|
|
4
5
|
export declare function assertIsBase58EncodedAddress(putativeBase58EncodedAddress: string): asserts putativeBase58EncodedAddress is Base58EncodedAddress<typeof putativeBase58EncodedAddress>;
|
|
6
|
+
export declare function getBase58EncodedAddressCodec(config?: Readonly<{
|
|
7
|
+
description: string;
|
|
8
|
+
}>): Serializer<Base58EncodedAddress>;
|
|
9
|
+
export declare function getBase58EncodedAddressComparator(): (x: string, y: string) => number;
|
|
5
10
|
//# sourceMappingURL=base58.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function assertKeyGenerationIsAvailable(): Promise<void>;
|
|
2
|
+
export declare function assertKeyExporterIsAvailable(): Promise<void>;
|
|
3
|
+
export declare function assertSigningCapabilityIsAvailable(): Promise<void>;
|
|
4
|
+
export declare function assertVerificationCapabilityIsAvailable(): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=guard.d.ts.map
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/keys",
|
|
3
|
-
"version": "2.0.0-experimental.
|
|
3
|
+
"version": "2.0.0-experimental.cb1a5a0",
|
|
4
4
|
"description": "Helpers for generating and transforming key material",
|
|
5
5
|
"exports": {
|
|
6
6
|
"browser": {
|
|
@@ -45,11 +45,17 @@
|
|
|
45
45
|
"supports bigint and not dead",
|
|
46
46
|
"maintained node versions"
|
|
47
47
|
],
|
|
48
|
+
"engine": {
|
|
49
|
+
"node": ">=17.4"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@metaplex-foundation/umi-serializers": "^0.8.2"
|
|
53
|
+
},
|
|
48
54
|
"devDependencies": {
|
|
49
|
-
"@solana/eslint-config-solana": "^1.0.
|
|
55
|
+
"@solana/eslint-config-solana": "^1.0.1",
|
|
50
56
|
"@swc/core": "^1.3.18",
|
|
51
|
-
"@swc/jest": "^0.2.
|
|
52
|
-
"@types/jest": "^29.5.
|
|
57
|
+
"@swc/jest": "^0.2.26",
|
|
58
|
+
"@types/jest": "^29.5.2",
|
|
53
59
|
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
|
54
60
|
"@typescript-eslint/parser": "^5.57.1",
|
|
55
61
|
"agadoo": "^3.0.0",
|
|
@@ -57,15 +63,15 @@
|
|
|
57
63
|
"eslint-plugin-jest": "^27.1.5",
|
|
58
64
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
59
65
|
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
60
|
-
"jest": "^29.
|
|
61
|
-
"jest-environment-jsdom": "^29.
|
|
62
|
-
"jest-runner-eslint": "^2.
|
|
66
|
+
"jest": "^29.6.1",
|
|
67
|
+
"jest-environment-jsdom": "^29.6.0",
|
|
68
|
+
"jest-runner-eslint": "^2.1.0",
|
|
63
69
|
"jest-runner-prettier": "^1.0.0",
|
|
64
70
|
"postcss": "^8.4.12",
|
|
65
|
-
"prettier": "^2.
|
|
71
|
+
"prettier": "^2.8.8",
|
|
66
72
|
"ts-node": "^10.9.1",
|
|
67
73
|
"tsup": "6.7.0",
|
|
68
|
-
"typescript": "^5.0.
|
|
74
|
+
"typescript": "^5.0.4",
|
|
69
75
|
"version-from-git": "^1.1.1",
|
|
70
76
|
"build-scripts": "0.0.0",
|
|
71
77
|
"test-config": "0.0.0",
|
|
@@ -79,9 +85,6 @@
|
|
|
79
85
|
}
|
|
80
86
|
]
|
|
81
87
|
},
|
|
82
|
-
"dependencies": {
|
|
83
|
-
"bs58": "^5.0.0"
|
|
84
|
-
},
|
|
85
88
|
"scripts": {
|
|
86
89
|
"compile:js": "tsup --config build-scripts/tsup.config.library.ts",
|
|
87
90
|
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
|