@solana/keys 2.0.0-experimental.fbdf21a → 2.0.0-experimental.fc4e943

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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2018 Solana Labs, Inc
1
+ Copyright (c) 2023 Solana Labs, Inc
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -18,35 +18,44 @@ This package contains utilities for validating, generating, and manipulating add
18
18
 
19
19
  ## Types
20
20
 
21
- ### `Base58EncodedAddress`
21
+ ### `Ed25519Signature`
22
22
 
23
- This type represents a string that validates as a Solana address or public key. Functions that require well-formed addresses should specify their inputs in terms of this type.
23
+ This type represents a 64-byte Ed25519 signature of some data with a private key.
24
24
 
25
- Whenever you need to validate an arbitrary string as a base58-encoded address, use the `assertIsBase58EncodedAddress()` function in this package.
25
+ Whenever you need to verify that a particular signature is, in fact, the one that would have been produced by signing some known bytes using the private key associated with some known public key, use the `verifySignature()` function in this package.
26
26
 
27
27
  ## Functions
28
28
 
29
- ### `assertIsBase58EncodedAddress()`
29
+ ### `generateKeyPair()`
30
30
 
31
- Client applications primarily deal with addresses and public keys in the form of base58-encoded strings. Addresses and public keys returned from the RPC API conform to the type `Base58EncodedAddress`. You can use a value of that type wherever a base58-encoded address or key is expected.
31
+ Generates an Ed25519 public/private key pair for use with other methods in this package that accept `CryptoKey` objects.
32
32
 
33
- From time to time you might acquire a string, that you expect to validate as an address, from an untrusted network API or user input. To assert that such an arbitrary string is a base58-encoded address, use the `assertIsBase58EncodedAddress` function.
33
+ ```ts
34
+ import { generateKeyPair } from '@solana/keys';
35
+
36
+ const { privateKey, publicKey } = await generateKeyPair();
37
+ ```
38
+
39
+ ### `signBytes()`
40
+
41
+ Given a private `CryptoKey` and a `Uint8Array` of bytes, this method will return the 64-byte Ed25519 signature of that data as a `Uint8Array`.
42
+
43
+ ```ts
44
+ import { signBytes } from '@solana/keys';
45
+
46
+ const data = new Uint8Array([1, 2, 3]);
47
+ const signature = await signBytes(privateKey, data);
48
+ ```
49
+
50
+ ### `verifySignature()`
51
+
52
+ Given a public `CryptoKey`, an `Ed25519Signature`, and a `Uint8Array` of bytes, this method will return `true` if the signature was produced by signing the bytes using the private key associated with the public key, and `false` otherwise.
34
53
 
35
54
  ```ts
36
- import { assertIsBase58EncodedAddress } from '@solana/web3.js`;
37
-
38
- // Imagine a function that fetches an account's balance when a user submits a form.
39
- function handleSubmit() {
40
- // We know only that what the user typed conforms to the `string` type.
41
- const address: string = accountAddressInput.value;
42
- try {
43
- // If this type assertion function doesn't throw, then
44
- // Typescript will upcast `address` to `Base58EncodedAddress`.
45
- assertIsBase58EncodedAddress(address);
46
- // At this point, `address` is a `Base58EncodedAddress` that can be used with the RPC.
47
- const balanceInLamports = await rpc.getBalance(address).send();
48
- } catch (e) {
49
- // `address` turned out not to be a base58-encoded address
50
- }
55
+ import { verifySignature } from '@solana/keys';
56
+
57
+ const data = new Uint8Array([1, 2, 3]);
58
+ if (!(await verifySignature(publicKey, signature, data))) {
59
+ throw new Error('The data were *not* signed by the private key associated with `publicKey`');
51
60
  }
52
61
  ```
@@ -1,40 +1,34 @@
1
1
  'use strict';
2
2
 
3
- var umiSerializersEncodings = require('@metaplex-foundation/umi-serializers-encodings');
3
+ var assertions = require('@solana/assertions');
4
4
 
5
- // src/base58.ts
6
- function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
7
- try {
8
- if (
9
- // Lowest address (32 bytes of zeroes)
10
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
11
- putativeBase58EncodedAddress.length > 44
12
- ) {
13
- throw new Error("Expected input string to decode to a byte array of length 32.");
14
- }
15
- const bytes = umiSerializersEncodings.base58.serialize(putativeBase58EncodedAddress);
16
- const numBytes = bytes.byteLength;
17
- if (numBytes !== 32) {
18
- throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
19
- }
20
- } catch (e) {
21
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
22
- cause: e
23
- });
24
- }
5
+ // src/key-pair.ts
6
+ async function generateKeyPair() {
7
+ await assertions.assertKeyGenerationIsAvailable();
8
+ const keyPair = await crypto.subtle.generateKey(
9
+ /* algorithm */
10
+ "Ed25519",
11
+ // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
12
+ /* extractable */
13
+ false,
14
+ // Prevents the bytes of the private key from being visible to JS.
15
+ /* allowed uses */
16
+ ["sign", "verify"]
17
+ );
18
+ return keyPair;
25
19
  }
26
- function getBase58EncodedAddressComparator() {
27
- return new Intl.Collator("en", {
28
- caseFirst: "lower",
29
- ignorePunctuation: false,
30
- localeMatcher: "best fit",
31
- numeric: false,
32
- sensitivity: "variant",
33
- usage: "sort"
34
- }).compare;
20
+ async function signBytes(key, data) {
21
+ await assertions.assertSigningCapabilityIsAvailable();
22
+ const signedData = await crypto.subtle.sign("Ed25519", key, data);
23
+ return new Uint8Array(signedData);
24
+ }
25
+ async function verifySignature(key, signature, data) {
26
+ await assertions.assertVerificationCapabilityIsAvailable();
27
+ return await crypto.subtle.verify("Ed25519", key, signature, data);
35
28
  }
36
29
 
37
- exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
38
- exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
30
+ exports.generateKeyPair = generateKeyPair;
31
+ exports.signBytes = signBytes;
32
+ exports.verifySignature = verifySignature;
39
33
  //# sourceMappingURL=out.js.map
40
34
  //# sourceMappingURL=index.browser.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/base58.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc;AAMhB,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,oCAAsE;AAClF,SAAO,IAAI,KAAK,SAAS,MAAM;AAAA,IAC3B,WAAW;AAAA,IACX,mBAAmB;AAAA,IACnB,eAAe;AAAA,IACf,SAAS;AAAA,IACT,aAAa;AAAA,IACb,OAAO;AAAA,EACX,CAAC,EAAE;AACP","sourcesContent":["import { base58 } from '@metaplex-foundation/umi-serializers-encodings';\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 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"]}
1
+ {"version":3,"sources":["../src/key-pair.ts","../src/signatures.ts"],"names":[],"mappings":";AAAA,SAAS,sCAAsC;AAE/C,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;;;ACVA,SAAS,oCAAoC,+CAA+C;AAI5F,eAAsB,UAAU,KAAgB,MAA6C;AACzF,QAAM,mCAAmC;AACzC,QAAM,aAAa,MAAM,OAAO,OAAO,KAAK,WAAW,KAAK,IAAI;AAChE,SAAO,IAAI,WAAW,UAAU;AACpC;AAEA,eAAsB,gBAAgB,KAAgB,WAA6B,MAAoC;AACnH,QAAM,wCAAwC;AAC9C,SAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK,WAAW,IAAI;AACrE","sourcesContent":["import { assertKeyGenerationIsAvailable } from '@solana/assertions';\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 { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\n\nexport type Ed25519Signature = Uint8Array & { readonly __brand: 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,37 +1,30 @@
1
- import { base58 } from '@metaplex-foundation/umi-serializers-encodings';
1
+ import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';
2
2
 
3
- // src/base58.ts
4
- function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
5
- try {
6
- if (
7
- // Lowest address (32 bytes of zeroes)
8
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
9
- putativeBase58EncodedAddress.length > 44
10
- ) {
11
- throw new Error("Expected input string to decode to a byte array of length 32.");
12
- }
13
- const bytes = base58.serialize(putativeBase58EncodedAddress);
14
- const numBytes = bytes.byteLength;
15
- if (numBytes !== 32) {
16
- throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
17
- }
18
- } catch (e) {
19
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
20
- cause: e
21
- });
22
- }
3
+ // src/key-pair.ts
4
+ async function generateKeyPair() {
5
+ await assertKeyGenerationIsAvailable();
6
+ const keyPair = await crypto.subtle.generateKey(
7
+ /* algorithm */
8
+ "Ed25519",
9
+ // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
10
+ /* extractable */
11
+ false,
12
+ // Prevents the bytes of the private key from being visible to JS.
13
+ /* allowed uses */
14
+ ["sign", "verify"]
15
+ );
16
+ return keyPair;
23
17
  }
24
- function getBase58EncodedAddressComparator() {
25
- return new Intl.Collator("en", {
26
- caseFirst: "lower",
27
- ignorePunctuation: false,
28
- localeMatcher: "best fit",
29
- numeric: false,
30
- sensitivity: "variant",
31
- usage: "sort"
32
- }).compare;
18
+ async function signBytes(key, data) {
19
+ await assertSigningCapabilityIsAvailable();
20
+ const signedData = await crypto.subtle.sign("Ed25519", key, data);
21
+ return new Uint8Array(signedData);
22
+ }
23
+ async function verifySignature(key, signature, data) {
24
+ await assertVerificationCapabilityIsAvailable();
25
+ return await crypto.subtle.verify("Ed25519", key, signature, data);
33
26
  }
34
27
 
35
- export { assertIsBase58EncodedAddress, getBase58EncodedAddressComparator };
28
+ export { generateKeyPair, signBytes, verifySignature };
36
29
  //# sourceMappingURL=out.js.map
37
30
  //# sourceMappingURL=index.browser.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/base58.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc;AAMhB,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,oCAAsE;AAClF,SAAO,IAAI,KAAK,SAAS,MAAM;AAAA,IAC3B,WAAW;AAAA,IACX,mBAAmB;AAAA,IACnB,eAAe;AAAA,IACf,SAAS;AAAA,IACT,aAAa;AAAA,IACb,OAAO;AAAA,EACX,CAAC,EAAE;AACP","sourcesContent":["import { base58 } from '@metaplex-foundation/umi-serializers-encodings';\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 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"]}
1
+ {"version":3,"sources":["../src/key-pair.ts","../src/signatures.ts"],"names":[],"mappings":";AAAA,SAAS,sCAAsC;AAE/C,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;;;ACVA,SAAS,oCAAoC,+CAA+C;AAI5F,eAAsB,UAAU,KAAgB,MAA6C;AACzF,QAAM,mCAAmC;AACzC,QAAM,aAAa,MAAM,OAAO,OAAO,KAAK,WAAW,KAAK,IAAI;AAChE,SAAO,IAAI,WAAW,UAAU;AACpC;AAEA,eAAsB,gBAAgB,KAAgB,WAA6B,MAAoC;AACnH,QAAM,wCAAwC;AAC9C,SAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK,WAAW,IAAI;AACrE","sourcesContent":["import { assertKeyGenerationIsAvailable } from '@solana/assertions';\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 { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\n\nexport type Ed25519Signature = Uint8Array & { readonly __brand: 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"]}
@@ -2,114 +2,90 @@ this.globalThis = this.globalThis || {};
2
2
  this.globalThis.solanaWeb3 = (function (exports) {
3
3
  'use strict';
4
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-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
13
- var InvalidBaseStringError = class extends Error {
14
- constructor(value, base, cause) {
15
- const message = `Expected a string of base ${base}, got [${value}].`;
16
- super(message);
17
- __publicField(this, "name", "InvalidBaseStringError");
18
- this.cause = cause;
5
+ // ../assertions/dist/index.browser.js
6
+ function assertIsSecureContext() {
7
+ if (!globalThis.isSecureContext) {
8
+ throw new Error(
9
+ "Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
10
+ );
19
11
  }
20
- };
21
-
22
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
23
- var baseX = (alphabet) => {
24
- const base = alphabet.length;
25
- const baseBigInt = BigInt(base);
26
- return {
27
- description: `base${base}`,
28
- fixedSize: null,
29
- maxSize: null,
30
- serialize(value) {
31
- if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
32
- throw new InvalidBaseStringError(value, base);
33
- }
34
- if (value === "")
35
- return new Uint8Array();
36
- const chars = [...value];
37
- let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
38
- trailIndex = trailIndex === -1 ? chars.length : trailIndex;
39
- const leadingZeroes = Array(trailIndex).fill(0);
40
- if (trailIndex === chars.length)
41
- return Uint8Array.from(leadingZeroes);
42
- const tailChars = chars.slice(trailIndex);
43
- let base10Number = 0n;
44
- let baseXPower = 1n;
45
- for (let i = tailChars.length - 1; i >= 0; i -= 1) {
46
- base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
47
- baseXPower *= baseBigInt;
48
- }
49
- const tailBytes = [];
50
- while (base10Number > 0n) {
51
- tailBytes.unshift(Number(base10Number % 256n));
52
- base10Number /= 256n;
53
- }
54
- return Uint8Array.from(leadingZeroes.concat(tailBytes));
55
- },
56
- deserialize(buffer, offset = 0) {
57
- if (buffer.length === 0)
58
- return ["", 0];
59
- const bytes = buffer.slice(offset);
60
- let trailIndex = bytes.findIndex((n) => n !== 0);
61
- trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
62
- const leadingZeroes = alphabet[0].repeat(trailIndex);
63
- if (trailIndex === bytes.length)
64
- return [leadingZeroes, buffer.length];
65
- let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
66
- const tailChars = [];
67
- while (base10Number > 0n) {
68
- tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
69
- base10Number /= baseBigInt;
70
- }
71
- return [leadingZeroes + tailChars.join(""), buffer.length];
72
- }
73
- };
74
- };
75
-
76
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
77
- var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
78
-
79
- // src/base58.ts
80
- function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
81
- try {
82
- if (
83
- // Lowest address (32 bytes of zeroes)
84
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
85
- putativeBase58EncodedAddress.length > 44
86
- ) {
87
- throw new Error("Expected input string to decode to a byte array of length 32.");
88
- }
89
- const bytes = base58.serialize(putativeBase58EncodedAddress);
90
- const numBytes = bytes.byteLength;
91
- if (numBytes !== 32) {
92
- throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
93
- }
94
- } catch (e) {
95
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
96
- cause: e
12
+ }
13
+ var cachedEd25519Decision;
14
+ async function isEd25519CurveSupported(subtle) {
15
+ if (cachedEd25519Decision === void 0) {
16
+ cachedEd25519Decision = new Promise((resolve) => {
17
+ subtle.generateKey(
18
+ "Ed25519",
19
+ /* extractable */
20
+ false,
21
+ ["sign", "verify"]
22
+ ).catch(() => {
23
+ resolve(cachedEd25519Decision = false);
24
+ }).then(() => {
25
+ resolve(cachedEd25519Decision = true);
26
+ });
97
27
  });
98
28
  }
29
+ if (typeof cachedEd25519Decision === "boolean") {
30
+ return cachedEd25519Decision;
31
+ } else {
32
+ return await cachedEd25519Decision;
33
+ }
34
+ }
35
+ async function assertKeyGenerationIsAvailable() {
36
+ assertIsSecureContext();
37
+ if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
38
+ throw new Error("No key generation implementation could be found");
39
+ }
40
+ if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
41
+ throw new Error(
42
+ "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"
43
+ );
44
+ }
45
+ }
46
+ async function assertSigningCapabilityIsAvailable() {
47
+ assertIsSecureContext();
48
+ if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
49
+ throw new Error("No signing implementation could be found");
50
+ }
51
+ }
52
+ async function assertVerificationCapabilityIsAvailable() {
53
+ assertIsSecureContext();
54
+ if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
55
+ throw new Error("No signature verification implementation could be found");
56
+ }
57
+ }
58
+
59
+ // src/key-pair.ts
60
+ async function generateKeyPair() {
61
+ await assertKeyGenerationIsAvailable();
62
+ const keyPair = await crypto.subtle.generateKey(
63
+ /* algorithm */
64
+ "Ed25519",
65
+ // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
66
+ /* extractable */
67
+ false,
68
+ // Prevents the bytes of the private key from being visible to JS.
69
+ /* allowed uses */
70
+ ["sign", "verify"]
71
+ );
72
+ return keyPair;
73
+ }
74
+
75
+ // src/signatures.ts
76
+ async function signBytes(key, data) {
77
+ await assertSigningCapabilityIsAvailable();
78
+ const signedData = await crypto.subtle.sign("Ed25519", key, data);
79
+ return new Uint8Array(signedData);
99
80
  }
100
- function getBase58EncodedAddressComparator() {
101
- return new Intl.Collator("en", {
102
- caseFirst: "lower",
103
- ignorePunctuation: false,
104
- localeMatcher: "best fit",
105
- numeric: false,
106
- sensitivity: "variant",
107
- usage: "sort"
108
- }).compare;
81
+ async function verifySignature(key, signature, data) {
82
+ await assertVerificationCapabilityIsAvailable();
83
+ return await crypto.subtle.verify("Ed25519", key, signature, data);
109
84
  }
110
85
 
111
- exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
112
- exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
86
+ exports.generateKeyPair = generateKeyPair;
87
+ exports.signBytes = signBytes;
88
+ exports.verifySignature = verifySignature;
113
89
 
114
90
  return exports;
115
91
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/src/errors.ts","../../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/src/baseX.ts","../../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/src/base58.ts","../src/base58.ts"],"names":["InvalidBaseStringError","Error","constructor","value","base","cause","message","name","baseX","alphabet","length","baseBigInt","BigInt","description","fixedSize","maxSize","serialize","match","RegExp","Uint8Array","chars","trailIndex","findIndex","c","leadingZeroes","Array","fill","from","tailChars","slice","base10Number","baseXPower","i","indexOf","tailBytes","unshift","Number","concat","deserialize","buffer","offset","bytes","n","repeat","reduce","sum","byte","join","base58"],"mappings":";;;;;;;;AACO,IAAMA,yBAAN,cAAqCC,MAAM;EAKhDC,YAAYC,OAAeC,MAAcC,OAAe;AACtD,UAAMC,UAAW,6BAA4BF,cAAcD;AAC3D,UAAMG,OAAO;AANNC,gCAAe;AAOtB,SAAKF,QAAQA;EACf;AACF;;;ACHaG,IAAAA,QAASC,cAAyC;AAC7D,QAAML,OAAOK,SAASC;AACtB,QAAMC,aAAaC,OAAOR,IAAI;AAC9B,SAAO;IACLS,aAAc,OAAMT;IACpBU,WAAW;IACXC,SAAS;IACTC,UAAUb,OAA2B;AAEnC,UAAI,CAACA,MAAMc,MAAM,IAAIC,OAAQ,KAAIT,aAAa,CAAC,GAAG;AAChD,cAAM,IAAIT,uBAAuBG,OAAOC,IAAI;MAC9C;AACA,UAAID,UAAU;AAAI,eAAO,IAAIgB,WAAU;AAGvC,YAAMC,QAAQ,CAAC,GAAGjB,KAAK;AACvB,UAAIkB,aAAaD,MAAME,UAAWC,OAAMA,MAAMd,SAAS,CAAC,CAAC;AACzDY,mBAAaA,eAAe,KAAKD,MAAMV,SAASW;AAChD,YAAMG,gBAAgBC,MAAMJ,UAAU,EAAEK,KAAK,CAAC;AAC9C,UAAIL,eAAeD,MAAMV;AAAQ,eAAOS,WAAWQ,KAAKH,aAAa;AAGrE,YAAMI,YAAYR,MAAMS,MAAMR,UAAU;AACxC,UAAIS,eAAe;AACnB,UAAIC,aAAa;AACjB,eAASC,IAAIJ,UAAUlB,SAAS,GAAGsB,KAAK,GAAGA,KAAK,GAAG;AACjDF,wBAAgBC,aAAanB,OAAOH,SAASwB,QAAQL,UAAUI,CAAC,CAAC,CAAC;AAClED,sBAAcpB;MAChB;AAGA,YAAMuB,YAAY,CAAA;AAClB,aAAOJ,eAAe,IAAI;AACxBI,kBAAUC,QAAQC,OAAON,eAAe,IAAI,CAAC;AAC7CA,wBAAgB;MAClB;AACA,aAAOX,WAAWQ,KAAKH,cAAca,OAAOH,SAAS,CAAC;;IAExDI,YAAYC,QAAQC,SAAS,GAAqB;AAChD,UAAID,OAAO7B,WAAW;AAAG,eAAO,CAAC,IAAI,CAAC;AAGtC,YAAM+B,QAAQF,OAAOV,MAAMW,MAAM;AACjC,UAAInB,aAAaoB,MAAMnB,UAAWoB,OAAMA,MAAM,CAAC;AAC/CrB,mBAAaA,eAAe,KAAKoB,MAAM/B,SAASW;AAChD,YAAMG,gBAAgBf,SAAS,CAAC,EAAEkC,OAAOtB,UAAU;AACnD,UAAIA,eAAeoB,MAAM/B;AAAQ,eAAO,CAACc,eAAee,OAAO7B,MAAM;AAGrE,UAAIoB,eAAeW,MAChBZ,MAAMR,UAAU,EAChBuB,OAAO,CAACC,KAAKC,SAASD,MAAM,OAAOjC,OAAOkC,IAAI,GAAG,EAAE;AAGtD,YAAMlB,YAAY,CAAA;AAClB,aAAOE,eAAe,IAAI;AACxBF,kBAAUO,QAAQ1B,SAAS2B,OAAON,eAAenB,UAAU,CAAC,CAAC;AAC7DmB,wBAAgBnB;MAClB;AAEA,aAAO,CAACa,gBAAgBI,UAAUmB,KAAK,EAAE,GAAGR,OAAO7B,MAAM;IAC3D;;AAEJ;;;IChEasC,SAA6BxC,MACxC,4DAA4D;;;ACFvD,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,oCAAsE;AAClF,SAAO,IAAI,KAAK,SAAS,MAAM;AAAA,IAC3B,WAAW;AAAA,IACX,mBAAmB;AAAA,IACnB,eAAe;AAAA,IACf,SAAS;AAAA,IACT,aAAa;AAAA,IACb,OAAO;AAAA,EACX,CAAC,EAAE;AACP","sourcesContent":["/** @category Errors */\nexport class InvalidBaseStringError extends Error {\n readonly name: string = 'InvalidBaseStringError';\n\n readonly cause?: Error;\n\n constructor(value: string, base: number, cause?: Error) {\n const message = `Expected a string of base ${base}, got [${value}].`;\n super(message);\n this.cause = cause;\n }\n}\n","import type { Serializer } from '@metaplex-foundation/umi-serializers-core';\nimport { InvalidBaseStringError } from './errors';\n\n/**\n * A string serializer that uses a custom alphabet.\n * This can be used to create serializers for base58, base64, etc.\n * @category Serializers\n */\nexport const baseX = (alphabet: string): Serializer<string> => {\n const base = alphabet.length;\n const baseBigInt = BigInt(base);\n return {\n description: `base${base}`,\n fixedSize: null,\n maxSize: null,\n serialize(value: string): Uint8Array {\n // Check if the value is valid.\n if (!value.match(new RegExp(`^[${alphabet}]*$`))) {\n throw new InvalidBaseStringError(value, base);\n }\n if (value === '') return new Uint8Array();\n\n // Handle leading zeroes.\n const chars = [...value];\n let trailIndex = chars.findIndex((c) => c !== alphabet[0]);\n trailIndex = trailIndex === -1 ? chars.length : trailIndex;\n const leadingZeroes = Array(trailIndex).fill(0);\n if (trailIndex === chars.length) return Uint8Array.from(leadingZeroes);\n\n // From baseX to base10.\n const tailChars = chars.slice(trailIndex);\n let base10Number = 0n;\n let baseXPower = 1n;\n for (let i = tailChars.length - 1; i >= 0; i -= 1) {\n base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));\n baseXPower *= baseBigInt;\n }\n\n // From base10 to bytes.\n const tailBytes = [];\n while (base10Number > 0n) {\n tailBytes.unshift(Number(base10Number % 256n));\n base10Number /= 256n;\n }\n return Uint8Array.from(leadingZeroes.concat(tailBytes));\n },\n deserialize(buffer, offset = 0): [string, number] {\n if (buffer.length === 0) return ['', 0];\n\n // Handle leading zeroes.\n const bytes = buffer.slice(offset);\n let trailIndex = bytes.findIndex((n) => n !== 0);\n trailIndex = trailIndex === -1 ? bytes.length : trailIndex;\n const leadingZeroes = alphabet[0].repeat(trailIndex);\n if (trailIndex === bytes.length) return [leadingZeroes, buffer.length];\n\n // From bytes to base10.\n let base10Number = bytes\n .slice(trailIndex)\n .reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);\n\n // From base10 to baseX.\n const tailChars = [];\n while (base10Number > 0n) {\n tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);\n base10Number /= baseBigInt;\n }\n\n return [leadingZeroes + tailChars.join(''), buffer.length];\n },\n };\n};\n","import type { Serializer } from '@metaplex-foundation/umi-serializers-core';\nimport { baseX } from './baseX';\n\n/**\n * A string serializer that uses base58 encoding.\n * @category Serializers\n */\nexport const base58: Serializer<string> = baseX(\n '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'\n);\n","import { base58 } from '@metaplex-foundation/umi-serializers-encodings';\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 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"]}
1
+ {"version":3,"sources":["../../assertions/src/subtle-crypto.ts","../src/key-pair.ts","../src/signatures.ts"],"names":[],"mappings":";AAAA,SAAS,wBAAwB;AAC7B,MAAmB,CAAC,WAAW,iBAAiB;AAE5C,UAAM,IAAI;MACN;IAEJ;EACJ;AACJ;AAEA,IAAI;AACJ,eAAe,wBAAwB,QAAwC;AAC3E,MAAI,0BAA0B,QAAW;AACrC,4BAAwB,IAAI,QAAQ,CAAA,YAAW;AAC3C,aACK;QAAY;;QAA6B;QAAO,CAAC,QAAQ,QAAQ;MAAC,EAClE,MAAM,MAAM;AACT,gBAAS,wBAAwB,KAAM;MAC3C,CAAC,EACA,KAAK,MAAM;AACR,gBAAS,wBAAwB,IAAK;MAC1C,CAAC;IACT,CAAC;EACL;AACA,MAAI,OAAO,0BAA0B,WAAW;AAC5C,WAAO;EACX,OAAO;AACH,WAAO,MAAM;EACjB;AACJ;AAUA,eAAsB,iCAAiC;AACnD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,gBAAgB,YAAY;AAEzG,UAAM,IAAI,MAAM,iDAAiD;EACrE;AACA,MAAI,CAAE,MAAM,wBAAwB,WAAW,OAAO,MAAM,GAAI;AAE5D,UAAM,IAAI;MACN;IAKJ;EACJ;AACJ;AAUA,eAAsB,qCAAqC;AACvD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,SAAS,YAAY;AAElG,UAAM,IAAI,MAAM,0CAA0C;EAC9D;AACJ;AAEA,eAAsB,0CAA0C;AAC5D,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AAEpG,UAAM,IAAI,MAAM,yDAAyD;EAC7E;AACJ;;;AC7EA,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;;;ACNA,eAAsB,UAAU,KAAgB,MAA6C;AACzF,QAAM,mCAAmC;AACzC,QAAM,aAAa,MAAM,OAAO,OAAO,KAAK,WAAW,KAAK,IAAI;AAChE,SAAO,IAAI,WAAW,UAAU;AACpC;AAEA,eAAsB,gBAAgB,KAAgB,WAA6B,MAAoC;AACnH,QAAM,wCAAwC;AAC9C,SAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK,WAAW,IAAI;AACrE","sourcesContent":["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 assertDigestCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.digest !== 'function') {\n // TODO: Coded error.\n throw new Error('No digest implementation could be found');\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 '@solana/assertions';\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 { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\n\nexport type Ed25519Signature = Uint8Array & { readonly __brand: 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,37 +1,30 @@
1
- import { base58 } from '@metaplex-foundation/umi-serializers-encodings';
1
+ import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';
2
2
 
3
- // src/base58.ts
4
- function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
5
- try {
6
- if (
7
- // Lowest address (32 bytes of zeroes)
8
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
9
- putativeBase58EncodedAddress.length > 44
10
- ) {
11
- throw new Error("Expected input string to decode to a byte array of length 32.");
12
- }
13
- const bytes = base58.serialize(putativeBase58EncodedAddress);
14
- const numBytes = bytes.byteLength;
15
- if (numBytes !== 32) {
16
- throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
17
- }
18
- } catch (e) {
19
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
20
- cause: e
21
- });
22
- }
3
+ // src/key-pair.ts
4
+ async function generateKeyPair() {
5
+ await assertKeyGenerationIsAvailable();
6
+ const keyPair = await crypto.subtle.generateKey(
7
+ /* algorithm */
8
+ "Ed25519",
9
+ // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
10
+ /* extractable */
11
+ false,
12
+ // Prevents the bytes of the private key from being visible to JS.
13
+ /* allowed uses */
14
+ ["sign", "verify"]
15
+ );
16
+ return keyPair;
23
17
  }
24
- function getBase58EncodedAddressComparator() {
25
- return new Intl.Collator("en", {
26
- caseFirst: "lower",
27
- ignorePunctuation: false,
28
- localeMatcher: "best fit",
29
- numeric: false,
30
- sensitivity: "variant",
31
- usage: "sort"
32
- }).compare;
18
+ async function signBytes(key, data) {
19
+ await assertSigningCapabilityIsAvailable();
20
+ const signedData = await crypto.subtle.sign("Ed25519", key, data);
21
+ return new Uint8Array(signedData);
22
+ }
23
+ async function verifySignature(key, signature, data) {
24
+ await assertVerificationCapabilityIsAvailable();
25
+ return await crypto.subtle.verify("Ed25519", key, signature, data);
33
26
  }
34
27
 
35
- export { assertIsBase58EncodedAddress, getBase58EncodedAddressComparator };
28
+ export { generateKeyPair, signBytes, verifySignature };
36
29
  //# sourceMappingURL=out.js.map
37
30
  //# sourceMappingURL=index.native.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/base58.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc;AAMhB,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,oCAAsE;AAClF,SAAO,IAAI,KAAK,SAAS,MAAM;AAAA,IAC3B,WAAW;AAAA,IACX,mBAAmB;AAAA,IACnB,eAAe;AAAA,IACf,SAAS;AAAA,IACT,aAAa;AAAA,IACb,OAAO;AAAA,EACX,CAAC,EAAE;AACP","sourcesContent":["import { base58 } from '@metaplex-foundation/umi-serializers-encodings';\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 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"]}
1
+ {"version":3,"sources":["../src/key-pair.ts","../src/signatures.ts"],"names":[],"mappings":";AAAA,SAAS,sCAAsC;AAE/C,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;;;ACVA,SAAS,oCAAoC,+CAA+C;AAI5F,eAAsB,UAAU,KAAgB,MAA6C;AACzF,QAAM,mCAAmC;AACzC,QAAM,aAAa,MAAM,OAAO,OAAO,KAAK,WAAW,KAAK,IAAI;AAChE,SAAO,IAAI,WAAW,UAAU;AACpC;AAEA,eAAsB,gBAAgB,KAAgB,WAA6B,MAAoC;AACnH,QAAM,wCAAwC;AAC9C,SAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK,WAAW,IAAI;AACrE","sourcesContent":["import { assertKeyGenerationIsAvailable } from '@solana/assertions';\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 { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\n\nexport type Ed25519Signature = Uint8Array & { readonly __brand: 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,40 +1,34 @@
1
1
  'use strict';
2
2
 
3
- var umiSerializersEncodings = require('@metaplex-foundation/umi-serializers-encodings');
3
+ var assertions = require('@solana/assertions');
4
4
 
5
- // src/base58.ts
6
- function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
7
- try {
8
- if (
9
- // Lowest address (32 bytes of zeroes)
10
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
11
- putativeBase58EncodedAddress.length > 44
12
- ) {
13
- throw new Error("Expected input string to decode to a byte array of length 32.");
14
- }
15
- const bytes = umiSerializersEncodings.base58.serialize(putativeBase58EncodedAddress);
16
- const numBytes = bytes.byteLength;
17
- if (numBytes !== 32) {
18
- throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
19
- }
20
- } catch (e) {
21
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
22
- cause: e
23
- });
24
- }
5
+ // src/key-pair.ts
6
+ async function generateKeyPair() {
7
+ await assertions.assertKeyGenerationIsAvailable();
8
+ const keyPair = await crypto.subtle.generateKey(
9
+ /* algorithm */
10
+ "Ed25519",
11
+ // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
12
+ /* extractable */
13
+ false,
14
+ // Prevents the bytes of the private key from being visible to JS.
15
+ /* allowed uses */
16
+ ["sign", "verify"]
17
+ );
18
+ return keyPair;
25
19
  }
26
- function getBase58EncodedAddressComparator() {
27
- return new Intl.Collator("en", {
28
- caseFirst: "lower",
29
- ignorePunctuation: false,
30
- localeMatcher: "best fit",
31
- numeric: false,
32
- sensitivity: "variant",
33
- usage: "sort"
34
- }).compare;
20
+ async function signBytes(key, data) {
21
+ await assertions.assertSigningCapabilityIsAvailable();
22
+ const signedData = await crypto.subtle.sign("Ed25519", key, data);
23
+ return new Uint8Array(signedData);
24
+ }
25
+ async function verifySignature(key, signature, data) {
26
+ await assertions.assertVerificationCapabilityIsAvailable();
27
+ return await crypto.subtle.verify("Ed25519", key, signature, data);
35
28
  }
36
29
 
37
- exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
38
- exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
30
+ exports.generateKeyPair = generateKeyPair;
31
+ exports.signBytes = signBytes;
32
+ exports.verifySignature = verifySignature;
39
33
  //# sourceMappingURL=out.js.map
40
34
  //# sourceMappingURL=index.node.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/base58.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc;AAMhB,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,oCAAsE;AAClF,SAAO,IAAI,KAAK,SAAS,MAAM;AAAA,IAC3B,WAAW;AAAA,IACX,mBAAmB;AAAA,IACnB,eAAe;AAAA,IACf,SAAS;AAAA,IACT,aAAa;AAAA,IACb,OAAO;AAAA,EACX,CAAC,EAAE;AACP","sourcesContent":["import { base58 } from '@metaplex-foundation/umi-serializers-encodings';\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 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"]}
1
+ {"version":3,"sources":["../src/key-pair.ts","../src/signatures.ts"],"names":[],"mappings":";AAAA,SAAS,sCAAsC;AAE/C,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;;;ACVA,SAAS,oCAAoC,+CAA+C;AAI5F,eAAsB,UAAU,KAAgB,MAA6C;AACzF,QAAM,mCAAmC;AACzC,QAAM,aAAa,MAAM,OAAO,OAAO,KAAK,WAAW,KAAK,IAAI;AAChE,SAAO,IAAI,WAAW,UAAU;AACpC;AAEA,eAAsB,gBAAgB,KAAgB,WAA6B,MAAoC;AACnH,QAAM,wCAAwC;AAC9C,SAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK,WAAW,IAAI;AACrE","sourcesContent":["import { assertKeyGenerationIsAvailable } from '@solana/assertions';\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 { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\n\nexport type Ed25519Signature = Uint8Array & { readonly __brand: 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,37 +1,30 @@
1
- import { base58 } from '@metaplex-foundation/umi-serializers-encodings';
1
+ import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';
2
2
 
3
- // src/base58.ts
4
- function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
5
- try {
6
- if (
7
- // Lowest address (32 bytes of zeroes)
8
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
9
- putativeBase58EncodedAddress.length > 44
10
- ) {
11
- throw new Error("Expected input string to decode to a byte array of length 32.");
12
- }
13
- const bytes = base58.serialize(putativeBase58EncodedAddress);
14
- const numBytes = bytes.byteLength;
15
- if (numBytes !== 32) {
16
- throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
17
- }
18
- } catch (e) {
19
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
20
- cause: e
21
- });
22
- }
3
+ // src/key-pair.ts
4
+ async function generateKeyPair() {
5
+ await assertKeyGenerationIsAvailable();
6
+ const keyPair = await crypto.subtle.generateKey(
7
+ /* algorithm */
8
+ "Ed25519",
9
+ // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
10
+ /* extractable */
11
+ false,
12
+ // Prevents the bytes of the private key from being visible to JS.
13
+ /* allowed uses */
14
+ ["sign", "verify"]
15
+ );
16
+ return keyPair;
23
17
  }
24
- function getBase58EncodedAddressComparator() {
25
- return new Intl.Collator("en", {
26
- caseFirst: "lower",
27
- ignorePunctuation: false,
28
- localeMatcher: "best fit",
29
- numeric: false,
30
- sensitivity: "variant",
31
- usage: "sort"
32
- }).compare;
18
+ async function signBytes(key, data) {
19
+ await assertSigningCapabilityIsAvailable();
20
+ const signedData = await crypto.subtle.sign("Ed25519", key, data);
21
+ return new Uint8Array(signedData);
22
+ }
23
+ async function verifySignature(key, signature, data) {
24
+ await assertVerificationCapabilityIsAvailable();
25
+ return await crypto.subtle.verify("Ed25519", key, signature, data);
33
26
  }
34
27
 
35
- export { assertIsBase58EncodedAddress, getBase58EncodedAddressComparator };
28
+ export { generateKeyPair, signBytes, verifySignature };
36
29
  //# sourceMappingURL=out.js.map
37
30
  //# sourceMappingURL=index.node.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/base58.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc;AAMhB,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,oCAAsE;AAClF,SAAO,IAAI,KAAK,SAAS,MAAM;AAAA,IAC3B,WAAW;AAAA,IACX,mBAAmB;AAAA,IACnB,eAAe;AAAA,IACf,SAAS;AAAA,IACT,aAAa;AAAA,IACb,OAAO;AAAA,EACX,CAAC,EAAE;AACP","sourcesContent":["import { base58 } from '@metaplex-foundation/umi-serializers-encodings';\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 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"]}
1
+ {"version":3,"sources":["../src/key-pair.ts","../src/signatures.ts"],"names":[],"mappings":";AAAA,SAAS,sCAAsC;AAE/C,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;;;ACVA,SAAS,oCAAoC,+CAA+C;AAI5F,eAAsB,UAAU,KAAgB,MAA6C;AACzF,QAAM,mCAAmC;AACzC,QAAM,aAAa,MAAM,OAAO,OAAO,KAAK,WAAW,KAAK,IAAI;AAChE,SAAO,IAAI,WAAW,UAAU;AACpC;AAEA,eAAsB,gBAAgB,KAAgB,WAA6B,MAAoC;AACnH,QAAM,wCAAwC;AAC9C,SAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK,WAAW,IAAI;AACrE","sourcesContent":["import { assertKeyGenerationIsAvailable } from '@solana/assertions';\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 { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\n\nexport type Ed25519Signature = Uint8Array & { readonly __brand: 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"]}
@@ -2,10 +2,15 @@ this.globalThis = this.globalThis || {};
2
2
  this.globalThis.solanaWeb3 = (function (exports) {
3
3
  'use strict';
4
4
 
5
- var h=Object.defineProperty;var b=(e,r,t)=>r in e?h(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var x=(e,r,t)=>(b(e,typeof r!="symbol"?r+"":r,t),t);var m=class extends Error{constructor(t,s,i){let n=`Expected a string of base ${s}, got [${t}].`;super(n);x(this,"name","InvalidBaseStringError");this.cause=i;}};var p=e=>{let r=e.length,t=BigInt(r);return {description:`base${r}`,fixedSize:null,maxSize:null,serialize(s){if(!s.match(new RegExp(`^[${e}]*$`)))throw new m(s,r);if(s==="")return new Uint8Array;let i=[...s],n=i.findIndex(c=>c!==e[0]);n=n===-1?i.length:n;let o=Array(n).fill(0);if(n===i.length)return Uint8Array.from(o);let l=i.slice(n),a=0n,g=1n;for(let c=l.length-1;c>=0;c-=1)a+=g*BigInt(e.indexOf(l[c])),g*=t;let d=[];for(;a>0n;)d.unshift(Number(a%256n)),a/=256n;return Uint8Array.from(o.concat(d))},deserialize(s,i=0){if(s.length===0)return ["",0];let n=s.slice(i),o=n.findIndex(d=>d!==0);o=o===-1?n.length:o;let l=e[0].repeat(o);if(o===n.length)return [l,s.length];let a=n.slice(o).reduce((d,c)=>d*256n+BigInt(c),0n),g=[];for(;a>0n;)g.unshift(e[Number(a%t)]),a/=t;return [l+g.join(""),s.length]}}};var u=p("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");function D(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=u.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 P(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}
5
+ function n(){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 e;async function y(t){return e===void 0&&(e=new Promise(o=>{t.generateKey("Ed25519",!1,["sign","verify"]).catch(()=>{o(e=!1);}).then(()=>{o(e=!0);});})),typeof e=="boolean"?e:await e}async function a(){if(n(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.generateKey!="function")throw new Error("No key generation implementation could be found");if(!await y(globalThis.crypto.subtle))throw new Error(`This runtime does not support the generation of Ed25519 key pairs.
6
6
 
7
- exports.assertIsBase58EncodedAddress = D;
8
- exports.getBase58EncodedAddressComparator = P;
7
+ Install and import \`@solana/webcrypto-ed25519-polyfill\` before generating keys in environments that do not support Ed25519.
8
+
9
+ For a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20`)}async function s(){if(n(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.sign!="function")throw new Error("No signing implementation could be found")}async function l(){if(n(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.verify!="function")throw new Error("No signature verification implementation could be found")}async function d(){return await a(),await crypto.subtle.generateKey("Ed25519",!1,["sign","verify"])}async function m(t,o){await s();let r=await crypto.subtle.sign("Ed25519",t,o);return new Uint8Array(r)}async function w(t,o,r){return await l(),await crypto.subtle.verify("Ed25519",t,o,r)}
10
+
11
+ exports.generateKeyPair = d;
12
+ exports.signBytes = m;
13
+ exports.verifySignature = w;
9
14
 
10
15
  return exports;
11
16
 
@@ -1,2 +1,3 @@
1
- export * from './base58';
1
+ export * from './key-pair';
2
+ export * from './signatures';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare function generateKeyPair(): Promise<CryptoKeyPair>;
2
+ //# sourceMappingURL=key-pair.d.ts.map
@@ -0,0 +1,6 @@
1
+ export type Ed25519Signature = Uint8Array & {
2
+ readonly __brand: unique symbol;
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>;
6
+ //# sourceMappingURL=signatures.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/keys",
3
- "version": "2.0.0-experimental.fbdf21a",
3
+ "version": "2.0.0-experimental.fc4e943",
4
4
  "description": "Helpers for generating and transforming key material",
5
5
  "exports": {
6
6
  "browser": {
@@ -45,30 +45,29 @@
45
45
  "supports bigint and not dead",
46
46
  "maintained node versions"
47
47
  ],
48
+ "engine": {
49
+ "node": ">=17.4"
50
+ },
48
51
  "dependencies": {
49
- "@metaplex-foundation/umi-serializers-encodings": "^0.8.2"
52
+ "@solana/assertions": "2.0.0-experimental.fc4e943"
50
53
  },
51
54
  "devDependencies": {
52
- "@solana/eslint-config-solana": "^1.0.1",
53
- "@swc/core": "^1.3.18",
54
- "@swc/jest": "^0.2.26",
55
- "@types/jest": "^29.5.1",
56
- "@typescript-eslint/eslint-plugin": "^5.57.1",
57
- "@typescript-eslint/parser": "^5.57.1",
55
+ "@solana/eslint-config-solana": "^1.0.2",
56
+ "@swc/jest": "^0.2.28",
57
+ "@types/jest": "^29.5.5",
58
+ "@typescript-eslint/eslint-plugin": "^6.7.0",
59
+ "@typescript-eslint/parser": "^6.3.0",
58
60
  "agadoo": "^3.0.0",
59
- "eslint": "^8.37.0",
60
- "eslint-plugin-jest": "^27.1.5",
61
- "eslint-plugin-react-hooks": "^4.6.0",
61
+ "eslint": "^8.45.0",
62
+ "eslint-plugin-jest": "^27.2.3",
62
63
  "eslint-plugin-sort-keys-fix": "^1.1.2",
63
- "jest": "^29.5.0",
64
- "jest-environment-jsdom": "^29.5.0",
64
+ "jest": "^29.7.0",
65
+ "jest-environment-jsdom": "^29.6.4",
65
66
  "jest-runner-eslint": "^2.1.0",
66
67
  "jest-runner-prettier": "^1.0.0",
67
- "postcss": "^8.4.12",
68
- "prettier": "^2.8.8",
69
- "ts-node": "^10.9.1",
70
- "tsup": "6.7.0",
71
- "typescript": "^5.0.4",
68
+ "prettier": "^2.8",
69
+ "tsup": "7.2.0",
70
+ "typescript": "^5.2.2",
72
71
  "version-from-git": "^1.1.1",
73
72
  "build-scripts": "0.0.0",
74
73
  "test-config": "0.0.0",
@@ -87,11 +86,12 @@
87
86
  "compile:typedefs": "tsc -p ./tsconfig.declarations.json",
88
87
  "dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
89
88
  "publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
89
+ "style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
90
90
  "test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
91
91
  "test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
92
92
  "test:treeshakability:browser": "agadoo dist/index.browser.js",
93
- "test:treeshakability:native": "agadoo dist/index.node.js",
94
- "test:treeshakability:node": "agadoo dist/index.native.js",
93
+ "test:treeshakability:native": "agadoo dist/index.native.js",
94
+ "test:treeshakability:node": "agadoo dist/index.node.js",
95
95
  "test:typecheck": "tsc --noEmit",
96
96
  "test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",
97
97
  "test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent"
@@ -1,6 +0,0 @@
1
- export type Base58EncodedAddress<TAddress extends string = string> = TAddress & {
2
- readonly __base58EncodedAddress: unique symbol;
3
- };
4
- export declare function assertIsBase58EncodedAddress(putativeBase58EncodedAddress: string): asserts putativeBase58EncodedAddress is Base58EncodedAddress<typeof putativeBase58EncodedAddress>;
5
- export declare function getBase58EncodedAddressComparator(): (x: string, y: string) => number;
6
- //# sourceMappingURL=base58.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base58.d.ts","sourceRoot":"","sources":["../../src/base58.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,oBAAoB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,QAAQ,GAAG;IAC5E,QAAQ,CAAC,sBAAsB,EAAE,OAAO,MAAM,CAAC;CAClD,CAAC;AAEF,wBAAgB,4BAA4B,CACxC,4BAA4B,EAAE,MAAM,GACrC,OAAO,CAAC,4BAA4B,IAAI,oBAAoB,CAAC,OAAO,4BAA4B,CAAC,CAsBnG;AAED,wBAAgB,iCAAiC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CASpF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}