@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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../build-scripts/env-shim.ts","../src/base58.ts","../src/guard.ts","../src/key-pair.ts","../src/pubkey.ts","../src/signatures.ts"],"names":[],"mappings":"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","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(\n 'This runtime does not support the generation of Ed25519 key pairs.\\n\\nInstall and ' +\n 'import `@solana/webcrypto-ed25519-polyfill` before generating keys in ' +\n 'environments that do not support Ed25519.\\n\\nFor a list of runtimes that ' +\n 'currently support Ed25519 operations, visit ' +\n 'https://github.com/WICG/webcrypto-secure-curves/issues/20'\n );\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","import { Base58EncodedAddress, getBase58EncodedAddressCodec } from './base58';\nimport { assertKeyExporterIsAvailable } from './guard';\n\nexport async function getBase58EncodedAddressFromPublicKey(publicKey: CryptoKey): Promise<Base58EncodedAddress> {\n await assertKeyExporterIsAvailable();\n if (publicKey.type !== 'public' || publicKey.algorithm.name !== 'Ed25519') {\n // TODO: Coded error.\n throw new Error('The `CryptoKey` must be an `Ed25519` public key');\n }\n const publicKeyBytes = await crypto.subtle.exportKey('raw', publicKey);\n const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));\n return base58EncodedAddress;\n}\n","import { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from './guard';\n\nexport type Ed25519Signature = Uint8Array & { readonly __ed25519Signature: unique symbol };\n\nexport async function signBytes(key: CryptoKey, data: Uint8Array): Promise<Ed25519Signature> {\n await assertSigningCapabilityIsAvailable();\n const signedData = await crypto.subtle.sign('Ed25519', key, data);\n return new Uint8Array(signedData) as Ed25519Signature;\n}\n\nexport async function verifySignature(key: CryptoKey, signature: Ed25519Signature, data: Uint8Array): Promise<boolean> {\n await assertVerificationCapabilityIsAvailable();\n return await crypto.subtle.verify('Ed25519', key, signature, data);\n}\n"]}
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"]}
@@ -1,5 +1,4 @@
1
- export * from './base58';
2
- export * from './key-pair';
3
- export * from './pubkey';
4
- export * from './signatures';
1
+ export * from './key-pair.js';
2
+ export * from './private-key.js';
3
+ export * from './signatures.js';
5
4
  //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -1,2 +1,3 @@
1
1
  export declare function generateKeyPair(): Promise<CryptoKeyPair>;
2
+ export declare function createKeyPairFromBytes(bytes: Uint8Array, extractable?: boolean): Promise<CryptoKeyPair>;
2
3
  //# sourceMappingURL=key-pair.d.ts.map
@@ -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,2 @@
1
+ export declare function createPrivateKeyFromBytes(bytes: Uint8Array, extractable?: boolean): Promise<CryptoKey>;
2
+ //# sourceMappingURL=private-key.d.ts.map
@@ -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 Ed25519Signature = Uint8Array & {
2
- readonly __ed25519Signature: unique symbol;
1
+ export type Signature = string & {
2
+ readonly __brand: unique symbol;
3
3
  };
4
- export declare function signBytes(key: CryptoKey, data: Uint8Array): Promise<Ed25519Signature>;
5
- export declare function verifySignature(key: CryptoKey, signature: Ed25519Signature, data: Uint8Array): Promise<boolean>;
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.0a6605f",
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
- "@metaplex-foundation/umi-serializers": "^0.8.5"
53
- },
54
- "devDependencies": {
55
- "@solana/eslint-config-solana": "^1.0.2",
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.library.ts",
90
- "compile:typedefs": "tsc -p ./tsconfig.declarations.json",
91
- "dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
92
- "publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
93
- "test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
94
- "test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
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.node.js",
97
- "test:treeshakability:node": "agadoo dist/index.native.js",
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