@solana/keys 2.0.0-experimental.0a6605f → 2.0.0-experimental.0af01ac
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/LICENSE +1 -1
- package/README.md +58 -22
- package/dist/index.browser.cjs +124 -116
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +117 -110
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +118 -98
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +125 -104
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +118 -98
- package/dist/index.node.js.map +1 -1
- package/dist/types/index.d.ts +3 -4
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/key-pair.d.ts +1 -0
- package/dist/types/key-pair.d.ts.map +1 -0
- package/dist/types/private-key.d.ts +2 -0
- package/dist/types/private-key.d.ts.map +1 -0
- package/dist/types/signatures.d.ts +10 -4
- package/dist/types/signatures.d.ts.map +1 -0
- package/package.json +17 -38
- package/dist/index.development.js +0 -418
- package/dist/index.development.js.map +0 -1
- package/dist/index.production.min.js +0 -21
- package/dist/types/base58.d.ts +0 -10
- package/dist/types/guard.d.ts +0 -5
- package/dist/types/pubkey.d.ts +0 -3
package/dist/index.node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["../src/key-pair.ts","../src/private-key.ts","../src/signatures.ts"],"names":["signature"],"mappings":"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","sourcesContent":["import { assertKeyGenerationIsAvailable } from '@solana/assertions';\nimport { SOLANA_ERROR__INVALID_KEYPAIR_BYTES, SolanaError } from '@solana/errors';\n\nimport { createPrivateKeyFromBytes } from './private-key';\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\nexport async function createKeyPairFromBytes(bytes: Uint8Array, extractable?: boolean): Promise<CryptoKeyPair> {\n if (bytes.byteLength !== 64) {\n throw new SolanaError(SOLANA_ERROR__INVALID_KEYPAIR_BYTES, { byteLength: bytes.byteLength });\n }\n const [publicKey, privateKey] = await Promise.all([\n crypto.subtle.importKey('raw', bytes.slice(32), 'Ed25519', /* extractable */ true, ['verify']),\n createPrivateKeyFromBytes(bytes.slice(0, 32), extractable),\n ]);\n return { privateKey, publicKey } as CryptoKeyPair;\n}\n","function addPkcs8Header(bytes: Uint8Array): Uint8Array {\n // prettier-ignore\n return new Uint8Array([\n /**\n * PKCS#8 header\n */\n 0x30, // ASN.1 sequence tag\n 0x2e, // Length of sequence (46 more bytes)\n\n 0x02, // ASN.1 integer tag\n 0x01, // Length of integer\n 0x00, // Version number\n\n 0x30, // ASN.1 sequence tag\n 0x05, // Length of sequence\n 0x06, // ASN.1 object identifier tag\n 0x03, // Length of object identifier\n // Edwards curve algorithms identifier https://oid-rep.orange-labs.fr/get/1.3.101.112\n 0x2b, // iso(1) / identified-organization(3) (The first node is multiplied by the decimal 40 and the result is added to the value of the second node)\n 0x65, // thawte(101)\n // Ed25519 identifier\n 0x70, // id-Ed25519(112)\n\n /**\n * Private key payload\n */\n 0x04, // ASN.1 octet string tag\n 0x22, // String length (34 more bytes)\n\n // Private key bytes as octet string\n 0x04, // ASN.1 octet string tag\n 0x20, // String length (32 bytes)\n\n ...bytes\n ]);\n}\n\nexport async function createPrivateKeyFromBytes(bytes: Uint8Array, extractable?: boolean): Promise<CryptoKey> {\n if (bytes.byteLength !== 32) {\n // TODO: Coded error.\n throw new Error('Private key bytes must be of length 32');\n }\n const privateKeyBytesPkcs8 = addPkcs8Header(bytes);\n return await crypto.subtle.importKey('pkcs8', privateKeyBytesPkcs8, 'Ed25519', extractable ?? false, ['sign']);\n}\n","import { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\nimport { Encoder } from '@solana/codecs-core';\nimport { getBase58Encoder } from '@solana/codecs-strings';\n\nexport type Signature = string & { readonly __brand: unique symbol };\nexport type SignatureBytes = Uint8Array & { readonly __brand: unique symbol };\n\nlet base58Encoder: Encoder<string> | undefined;\n\nexport function assertIsSignature(putativeSignature: string): asserts putativeSignature is Signature {\n if (!base58Encoder) base58Encoder = getBase58Encoder();\n\n try {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest value (64 bytes of zeroes)\n putativeSignature.length < 64 ||\n // Highest value (64 bytes of 255)\n putativeSignature.length > 88\n ) {\n throw new Error('Expected input string to decode to a byte array of length 64.');\n }\n // Slow-path; actually attempt to decode the input string.\n const bytes = base58Encoder.encode(putativeSignature);\n const numBytes = bytes.byteLength;\n if (numBytes !== 64) {\n throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);\n }\n } catch (e) {\n throw new Error(`\\`${putativeSignature}\\` is not a signature`, {\n cause: e,\n });\n }\n}\n\nexport function isSignature(putativeSignature: string): putativeSignature is Signature {\n if (!base58Encoder) base58Encoder = getBase58Encoder();\n\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest value (64 bytes of zeroes)\n putativeSignature.length < 64 ||\n // Highest value (64 bytes of 255)\n putativeSignature.length > 88\n ) {\n return false;\n }\n // Slow-path; actually attempt to decode the input string.\n const bytes = base58Encoder.encode(putativeSignature);\n const numBytes = bytes.byteLength;\n if (numBytes !== 64) {\n return false;\n }\n return true;\n}\n\nexport async function signBytes(key: CryptoKey, data: Uint8Array): Promise<SignatureBytes> {\n await assertSigningCapabilityIsAvailable();\n const signedData = await crypto.subtle.sign('Ed25519', key, data);\n return new Uint8Array(signedData) as SignatureBytes;\n}\n\nexport function signature(putativeSignature: string): Signature {\n assertIsSignature(putativeSignature);\n return putativeSignature;\n}\n\nexport async function verifySignature(key: CryptoKey, signature: SignatureBytes, data: Uint8Array): Promise<boolean> {\n await assertVerificationCapabilityIsAvailable();\n return await crypto.subtle.verify('Ed25519', key, signature, data);\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
|
package/dist/types/key-pair.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-pair.d.ts","sourceRoot":"","sources":["../../src/key-pair.ts"],"names":[],"mappings":"AAKA,wBAAsB,eAAe,IAAI,OAAO,CAAC,aAAa,CAAC,CAQ9D;AAED,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAS7G"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private-key.d.ts","sourceRoot":"","sources":["../../src/private-key.ts"],"names":[],"mappings":"AAqCA,wBAAsB,yBAAyB,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAO5G"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
export type
|
|
2
|
-
readonly
|
|
1
|
+
export type Signature = string & {
|
|
2
|
+
readonly __brand: unique symbol;
|
|
3
3
|
};
|
|
4
|
-
export
|
|
5
|
-
|
|
4
|
+
export type SignatureBytes = Uint8Array & {
|
|
5
|
+
readonly __brand: unique symbol;
|
|
6
|
+
};
|
|
7
|
+
export declare function assertIsSignature(putativeSignature: string): asserts putativeSignature is Signature;
|
|
8
|
+
export declare function isSignature(putativeSignature: string): putativeSignature is Signature;
|
|
9
|
+
export declare function signBytes(key: CryptoKey, data: Uint8Array): Promise<SignatureBytes>;
|
|
10
|
+
export declare function signature(putativeSignature: string): Signature;
|
|
11
|
+
export declare function verifySignature(key: CryptoKey, signature: SignatureBytes, data: Uint8Array): Promise<boolean>;
|
|
6
12
|
//# sourceMappingURL=signatures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signatures.d.ts","sourceRoot":"","sources":["../../src/signatures.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,MAAM,CAAA;CAAE,CAAC;AACrE,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,MAAM,CAAA;CAAE,CAAC;AAI9E,wBAAgB,iBAAiB,CAAC,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,IAAI,SAAS,CAwBnG;AAED,wBAAgB,WAAW,CAAC,iBAAiB,EAAE,MAAM,GAAG,iBAAiB,IAAI,SAAS,CAmBrF;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAIzF;AAED,wBAAgB,SAAS,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAG9D;AAED,wBAAsB,eAAe,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAGnH"}
|
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.0af01ac",
|
|
4
4
|
"description": "Helpers for generating and transforming key material",
|
|
5
5
|
"exports": {
|
|
6
6
|
"browser": {
|
|
@@ -49,33 +49,10 @@
|
|
|
49
49
|
"node": ">=17.4"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"@solana/
|
|
56
|
-
"@swc/core": "^1.3.18",
|
|
57
|
-
"@swc/jest": "^0.2.26",
|
|
58
|
-
"@types/jest": "^29.5.3",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
60
|
-
"@typescript-eslint/parser": "^6.0.0",
|
|
61
|
-
"agadoo": "^3.0.0",
|
|
62
|
-
"eslint": "^8.45.0",
|
|
63
|
-
"eslint-plugin-jest": "^27.2.3",
|
|
64
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
65
|
-
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
66
|
-
"jest": "^29.6.1",
|
|
67
|
-
"jest-environment-jsdom": "^29.6.0",
|
|
68
|
-
"jest-runner-eslint": "^2.1.0",
|
|
69
|
-
"jest-runner-prettier": "^1.0.0",
|
|
70
|
-
"postcss": "^8.4.12",
|
|
71
|
-
"prettier": "^2.8.8",
|
|
72
|
-
"ts-node": "^10.9.1",
|
|
73
|
-
"tsup": "6.7.0",
|
|
74
|
-
"typescript": "^5.1.6",
|
|
75
|
-
"version-from-git": "^1.1.1",
|
|
76
|
-
"build-scripts": "0.0.0",
|
|
77
|
-
"test-config": "0.0.0",
|
|
78
|
-
"tsconfig": "0.0.0"
|
|
52
|
+
"@solana/assertions": "2.0.0-experimental.0af01ac",
|
|
53
|
+
"@solana/codecs-core": "2.0.0-experimental.0af01ac",
|
|
54
|
+
"@solana/codecs-strings": "2.0.0-experimental.0af01ac",
|
|
55
|
+
"@solana/errors": "2.0.0-experimental.0af01ac"
|
|
79
56
|
},
|
|
80
57
|
"bundlewatch": {
|
|
81
58
|
"defaultCompression": "gzip",
|
|
@@ -86,17 +63,19 @@
|
|
|
86
63
|
]
|
|
87
64
|
},
|
|
88
65
|
"scripts": {
|
|
89
|
-
"compile:js": "tsup --config build-scripts/tsup.config.
|
|
90
|
-
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
|
|
91
|
-
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
92
|
-
"publish-
|
|
93
|
-
"
|
|
94
|
-
"
|
|
66
|
+
"compile:js": "tsup --config build-scripts/tsup.config.package.ts",
|
|
67
|
+
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/@solana/build-scripts/add-js-extension-to-types.mjs",
|
|
68
|
+
"dev": "jest -c node_modules/@solana/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
69
|
+
"publish-impl": "npm view $npm_package_name@$npm_package_version > /dev/null 2>&1 || pnpm publish --tag experimental --access public --no-git-checks",
|
|
70
|
+
"publish-packages": "pnpm prepublishOnly && pnpm publish-impl",
|
|
71
|
+
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
|
|
72
|
+
"test:lint": "jest -c node_modules/@solana/test-config/jest-lint.config.ts --rootDir . --silent",
|
|
73
|
+
"test:prettier": "jest -c node_modules/@solana/test-config/jest-prettier.config.ts --rootDir . --silent",
|
|
95
74
|
"test:treeshakability:browser": "agadoo dist/index.browser.js",
|
|
96
|
-
"test:treeshakability:native": "agadoo dist/index.
|
|
97
|
-
"test:treeshakability:node": "agadoo dist/index.
|
|
75
|
+
"test:treeshakability:native": "agadoo dist/index.native.js",
|
|
76
|
+
"test:treeshakability:node": "agadoo dist/index.node.js",
|
|
98
77
|
"test:typecheck": "tsc --noEmit",
|
|
99
|
-
"test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",
|
|
100
|
-
"test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent"
|
|
78
|
+
"test:unit:browser": "jest -c node_modules/@solana/test-config/jest-unit.config.browser.ts --rootDir . --silent",
|
|
79
|
+
"test:unit:node": "jest -c node_modules/@solana/test-config/jest-unit.config.node.ts --rootDir . --silent"
|
|
101
80
|
}
|
|
102
81
|
}
|
|
@@ -1,418 +0,0 @@
|
|
|
1
|
-
this.globalThis = this.globalThis || {};
|
|
2
|
-
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __publicField = (obj, key, value) => {
|
|
8
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
-
return value;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
|
|
13
|
-
var mergeBytes = (bytesArr) => {
|
|
14
|
-
const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
|
|
15
|
-
const result = new Uint8Array(totalLength);
|
|
16
|
-
let offset = 0;
|
|
17
|
-
bytesArr.forEach((arr) => {
|
|
18
|
-
result.set(arr, offset);
|
|
19
|
-
offset += arr.length;
|
|
20
|
-
});
|
|
21
|
-
return result;
|
|
22
|
-
};
|
|
23
|
-
var padBytes = (bytes, length) => {
|
|
24
|
-
if (bytes.length >= length)
|
|
25
|
-
return bytes;
|
|
26
|
-
const paddedBytes = new Uint8Array(length).fill(0);
|
|
27
|
-
paddedBytes.set(bytes);
|
|
28
|
-
return paddedBytes;
|
|
29
|
-
};
|
|
30
|
-
var fixBytes = (bytes, length) => padBytes(bytes.slice(0, length), length);
|
|
31
|
-
|
|
32
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
|
|
33
|
-
var DeserializingEmptyBufferError = class extends Error {
|
|
34
|
-
constructor(serializer) {
|
|
35
|
-
super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
|
|
36
|
-
__publicField(this, "name", "DeserializingEmptyBufferError");
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
var NotEnoughBytesError = class extends Error {
|
|
40
|
-
constructor(serializer, expected, actual) {
|
|
41
|
-
super(`Serializer [${serializer}] expected ${expected} bytes, got ${actual}.`);
|
|
42
|
-
__publicField(this, "name", "NotEnoughBytesError");
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
|
|
47
|
-
function fixSerializer(serializer, fixedBytes, description) {
|
|
48
|
-
return {
|
|
49
|
-
description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
|
|
50
|
-
fixedSize: fixedBytes,
|
|
51
|
-
maxSize: fixedBytes,
|
|
52
|
-
serialize: (value) => fixBytes(serializer.serialize(value), fixedBytes),
|
|
53
|
-
deserialize: (buffer, offset = 0) => {
|
|
54
|
-
buffer = buffer.slice(offset, offset + fixedBytes);
|
|
55
|
-
if (buffer.length < fixedBytes) {
|
|
56
|
-
throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
|
|
57
|
-
}
|
|
58
|
-
if (serializer.fixedSize !== null) {
|
|
59
|
-
buffer = fixBytes(buffer, serializer.fixedSize);
|
|
60
|
-
}
|
|
61
|
-
const [value] = serializer.deserialize(buffer, 0);
|
|
62
|
-
return [value, offset + fixedBytes];
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
|
|
68
|
-
var InvalidBaseStringError = class extends Error {
|
|
69
|
-
constructor(value, base, cause) {
|
|
70
|
-
const message = `Expected a string of base ${base}, got [${value}].`;
|
|
71
|
-
super(message);
|
|
72
|
-
__publicField(this, "name", "InvalidBaseStringError");
|
|
73
|
-
this.cause = cause;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
78
|
-
var baseX = (alphabet) => {
|
|
79
|
-
const base = alphabet.length;
|
|
80
|
-
const baseBigInt = BigInt(base);
|
|
81
|
-
return {
|
|
82
|
-
description: `base${base}`,
|
|
83
|
-
fixedSize: null,
|
|
84
|
-
maxSize: null,
|
|
85
|
-
serialize(value) {
|
|
86
|
-
if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
|
|
87
|
-
throw new InvalidBaseStringError(value, base);
|
|
88
|
-
}
|
|
89
|
-
if (value === "")
|
|
90
|
-
return new Uint8Array();
|
|
91
|
-
const chars = [...value];
|
|
92
|
-
let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
|
|
93
|
-
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
94
|
-
const leadingZeroes = Array(trailIndex).fill(0);
|
|
95
|
-
if (trailIndex === chars.length)
|
|
96
|
-
return Uint8Array.from(leadingZeroes);
|
|
97
|
-
const tailChars = chars.slice(trailIndex);
|
|
98
|
-
let base10Number = 0n;
|
|
99
|
-
let baseXPower = 1n;
|
|
100
|
-
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
101
|
-
base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
|
|
102
|
-
baseXPower *= baseBigInt;
|
|
103
|
-
}
|
|
104
|
-
const tailBytes = [];
|
|
105
|
-
while (base10Number > 0n) {
|
|
106
|
-
tailBytes.unshift(Number(base10Number % 256n));
|
|
107
|
-
base10Number /= 256n;
|
|
108
|
-
}
|
|
109
|
-
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
110
|
-
},
|
|
111
|
-
deserialize(buffer, offset = 0) {
|
|
112
|
-
if (buffer.length === 0)
|
|
113
|
-
return ["", 0];
|
|
114
|
-
const bytes = buffer.slice(offset);
|
|
115
|
-
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
116
|
-
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
117
|
-
const leadingZeroes = alphabet[0].repeat(trailIndex);
|
|
118
|
-
if (trailIndex === bytes.length)
|
|
119
|
-
return [leadingZeroes, buffer.length];
|
|
120
|
-
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
121
|
-
const tailChars = [];
|
|
122
|
-
while (base10Number > 0n) {
|
|
123
|
-
tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
|
|
124
|
-
base10Number /= baseBigInt;
|
|
125
|
-
}
|
|
126
|
-
return [leadingZeroes + tailChars.join(""), buffer.length];
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
|
|
132
|
-
var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
133
|
-
|
|
134
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
|
|
135
|
-
var removeNullCharacters = (value) => (
|
|
136
|
-
// eslint-disable-next-line no-control-regex
|
|
137
|
-
value.replace(/\u0000/g, "")
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
|
|
141
|
-
var utf8 = {
|
|
142
|
-
description: "utf8",
|
|
143
|
-
fixedSize: null,
|
|
144
|
-
maxSize: null,
|
|
145
|
-
serialize(value) {
|
|
146
|
-
return new TextEncoder().encode(value);
|
|
147
|
-
},
|
|
148
|
-
deserialize(buffer, offset = 0) {
|
|
149
|
-
const value = new TextDecoder().decode(buffer.slice(offset));
|
|
150
|
-
return [removeNullCharacters(value), buffer.length];
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
|
|
155
|
-
var Endian;
|
|
156
|
-
(function(Endian2) {
|
|
157
|
-
Endian2["Little"] = "le";
|
|
158
|
-
Endian2["Big"] = "be";
|
|
159
|
-
})(Endian || (Endian = {}));
|
|
160
|
-
|
|
161
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
|
|
162
|
-
var NumberOutOfRangeError = class extends RangeError {
|
|
163
|
-
constructor(serializer, min, max, actual) {
|
|
164
|
-
super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
|
|
165
|
-
__publicField(this, "name", "NumberOutOfRangeError");
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
|
|
170
|
-
function numberFactory(input) {
|
|
171
|
-
let littleEndian;
|
|
172
|
-
let defaultDescription = input.name;
|
|
173
|
-
if (input.size > 1) {
|
|
174
|
-
littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
|
|
175
|
-
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
176
|
-
}
|
|
177
|
-
return {
|
|
178
|
-
description: input.options.description ?? defaultDescription,
|
|
179
|
-
fixedSize: input.size,
|
|
180
|
-
maxSize: input.size,
|
|
181
|
-
serialize(value) {
|
|
182
|
-
if (input.range) {
|
|
183
|
-
assertRange(input.name, input.range[0], input.range[1], value);
|
|
184
|
-
}
|
|
185
|
-
const buffer = new ArrayBuffer(input.size);
|
|
186
|
-
input.set(new DataView(buffer), value, littleEndian);
|
|
187
|
-
return new Uint8Array(buffer);
|
|
188
|
-
},
|
|
189
|
-
deserialize(bytes, offset = 0) {
|
|
190
|
-
const slice = bytes.slice(offset, offset + input.size);
|
|
191
|
-
assertEnoughBytes("i8", slice, input.size);
|
|
192
|
-
const view = toDataView(slice);
|
|
193
|
-
return [input.get(view, littleEndian), offset + input.size];
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
var toArrayBuffer = (array) => array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset);
|
|
198
|
-
var toDataView = (array) => new DataView(toArrayBuffer(array));
|
|
199
|
-
var assertRange = (serializer, min, max, value) => {
|
|
200
|
-
if (value < min || value > max) {
|
|
201
|
-
throw new NumberOutOfRangeError(serializer, min, max, value);
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
var assertEnoughBytes = (serializer, bytes, expected) => {
|
|
205
|
-
if (bytes.length === 0) {
|
|
206
|
-
throw new DeserializingEmptyBufferError(serializer);
|
|
207
|
-
}
|
|
208
|
-
if (bytes.length < expected) {
|
|
209
|
-
throw new NotEnoughBytesError(serializer, expected, bytes.length);
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
|
|
214
|
-
var u32 = (options = {}) => numberFactory({
|
|
215
|
-
name: "u32",
|
|
216
|
-
size: 4,
|
|
217
|
-
range: [0, Number("0xffffffff")],
|
|
218
|
-
set: (view, value, le) => view.setUint32(0, Number(value), le),
|
|
219
|
-
get: (view, le) => view.getUint32(0, le),
|
|
220
|
-
options
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
|
|
224
|
-
function getSizeDescription(size) {
|
|
225
|
-
return typeof size === "object" ? size.description : `${size}`;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
|
|
229
|
-
function string(options = {}) {
|
|
230
|
-
const size = options.size ?? u32();
|
|
231
|
-
const encoding = options.encoding ?? utf8;
|
|
232
|
-
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
233
|
-
if (size === "variable") {
|
|
234
|
-
return {
|
|
235
|
-
...encoding,
|
|
236
|
-
description
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
if (typeof size === "number") {
|
|
240
|
-
return fixSerializer(encoding, size, description);
|
|
241
|
-
}
|
|
242
|
-
return {
|
|
243
|
-
description,
|
|
244
|
-
fixedSize: null,
|
|
245
|
-
maxSize: null,
|
|
246
|
-
serialize: (value) => {
|
|
247
|
-
const contentBytes = encoding.serialize(value);
|
|
248
|
-
const lengthBytes = size.serialize(contentBytes.length);
|
|
249
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
250
|
-
},
|
|
251
|
-
deserialize: (buffer, offset = 0) => {
|
|
252
|
-
if (buffer.slice(offset).length === 0) {
|
|
253
|
-
throw new DeserializingEmptyBufferError("string");
|
|
254
|
-
}
|
|
255
|
-
const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
|
|
256
|
-
const length = Number(lengthBigInt);
|
|
257
|
-
offset = lengthOffset;
|
|
258
|
-
const contentBuffer = buffer.slice(offset, offset + length);
|
|
259
|
-
if (contentBuffer.length < length) {
|
|
260
|
-
throw new NotEnoughBytesError("string", length, contentBuffer.length);
|
|
261
|
-
}
|
|
262
|
-
const [value, contentOffset] = encoding.deserialize(contentBuffer);
|
|
263
|
-
offset += contentOffset;
|
|
264
|
-
return [value, offset];
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// src/base58.ts
|
|
270
|
-
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
271
|
-
try {
|
|
272
|
-
if (
|
|
273
|
-
// Lowest address (32 bytes of zeroes)
|
|
274
|
-
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
275
|
-
putativeBase58EncodedAddress.length > 44
|
|
276
|
-
) {
|
|
277
|
-
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
278
|
-
}
|
|
279
|
-
const bytes = base58.serialize(putativeBase58EncodedAddress);
|
|
280
|
-
const numBytes = bytes.byteLength;
|
|
281
|
-
if (numBytes !== 32) {
|
|
282
|
-
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
283
|
-
}
|
|
284
|
-
} catch (e) {
|
|
285
|
-
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
286
|
-
cause: e
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
function getBase58EncodedAddressCodec(config) {
|
|
291
|
-
return string({
|
|
292
|
-
description: config?.description ?? ("A 32-byte account address" ),
|
|
293
|
-
encoding: base58,
|
|
294
|
-
size: 32
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
function getBase58EncodedAddressComparator() {
|
|
298
|
-
return new Intl.Collator("en", {
|
|
299
|
-
caseFirst: "lower",
|
|
300
|
-
ignorePunctuation: false,
|
|
301
|
-
localeMatcher: "best fit",
|
|
302
|
-
numeric: false,
|
|
303
|
-
sensitivity: "variant",
|
|
304
|
-
usage: "sort"
|
|
305
|
-
}).compare;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// src/guard.ts
|
|
309
|
-
function assertIsSecureContext() {
|
|
310
|
-
if (!globalThis.isSecureContext) {
|
|
311
|
-
throw new Error(
|
|
312
|
-
"Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
var cachedEd25519Decision;
|
|
317
|
-
async function isEd25519CurveSupported(subtle) {
|
|
318
|
-
if (cachedEd25519Decision === void 0) {
|
|
319
|
-
cachedEd25519Decision = new Promise((resolve) => {
|
|
320
|
-
subtle.generateKey(
|
|
321
|
-
"Ed25519",
|
|
322
|
-
/* extractable */
|
|
323
|
-
false,
|
|
324
|
-
["sign", "verify"]
|
|
325
|
-
).catch(() => {
|
|
326
|
-
resolve(cachedEd25519Decision = false);
|
|
327
|
-
}).then(() => {
|
|
328
|
-
resolve(cachedEd25519Decision = true);
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
if (typeof cachedEd25519Decision === "boolean") {
|
|
333
|
-
return cachedEd25519Decision;
|
|
334
|
-
} else {
|
|
335
|
-
return await cachedEd25519Decision;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
async function assertKeyGenerationIsAvailable() {
|
|
339
|
-
assertIsSecureContext();
|
|
340
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
341
|
-
throw new Error("No key generation implementation could be found");
|
|
342
|
-
}
|
|
343
|
-
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
344
|
-
throw new Error(
|
|
345
|
-
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
async function assertKeyExporterIsAvailable() {
|
|
350
|
-
assertIsSecureContext();
|
|
351
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
|
|
352
|
-
throw new Error("No key export implementation could be found");
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
async function assertSigningCapabilityIsAvailable() {
|
|
356
|
-
assertIsSecureContext();
|
|
357
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
358
|
-
throw new Error("No signing implementation could be found");
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
async function assertVerificationCapabilityIsAvailable() {
|
|
362
|
-
assertIsSecureContext();
|
|
363
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
|
|
364
|
-
throw new Error("No signature verification implementation could be found");
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// src/key-pair.ts
|
|
369
|
-
async function generateKeyPair() {
|
|
370
|
-
await assertKeyGenerationIsAvailable();
|
|
371
|
-
const keyPair = await crypto.subtle.generateKey(
|
|
372
|
-
/* algorithm */
|
|
373
|
-
"Ed25519",
|
|
374
|
-
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
375
|
-
/* extractable */
|
|
376
|
-
false,
|
|
377
|
-
// Prevents the bytes of the private key from being visible to JS.
|
|
378
|
-
/* allowed uses */
|
|
379
|
-
["sign", "verify"]
|
|
380
|
-
);
|
|
381
|
-
return keyPair;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// src/pubkey.ts
|
|
385
|
-
async function getBase58EncodedAddressFromPublicKey(publicKey) {
|
|
386
|
-
await assertKeyExporterIsAvailable();
|
|
387
|
-
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
|
|
388
|
-
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
389
|
-
}
|
|
390
|
-
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
391
|
-
const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
|
|
392
|
-
return base58EncodedAddress;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
// src/signatures.ts
|
|
396
|
-
async function signBytes(key, data) {
|
|
397
|
-
await assertSigningCapabilityIsAvailable();
|
|
398
|
-
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
399
|
-
return new Uint8Array(signedData);
|
|
400
|
-
}
|
|
401
|
-
async function verifySignature(key, signature, data) {
|
|
402
|
-
await assertVerificationCapabilityIsAvailable();
|
|
403
|
-
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
|
|
407
|
-
exports.generateKeyPair = generateKeyPair;
|
|
408
|
-
exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
|
|
409
|
-
exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
|
|
410
|
-
exports.getBase58EncodedAddressFromPublicKey = getBase58EncodedAddressFromPublicKey;
|
|
411
|
-
exports.signBytes = signBytes;
|
|
412
|
-
exports.verifySignature = verifySignature;
|
|
413
|
-
|
|
414
|
-
return exports;
|
|
415
|
-
|
|
416
|
-
})({});
|
|
417
|
-
//# sourceMappingURL=out.js.map
|
|
418
|
-
//# sourceMappingURL=index.development.js.map
|