@solana/keys 2.0.0-experimental.eefafdf → 2.0.0-experimental.ef09aec

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,44 +1,82 @@
1
1
  'use strict';
2
2
 
3
- var bs58 = require('bs58');
3
+ var assertions = require('@solana/assertions');
4
+ var codecsStrings = require('@solana/codecs-strings');
4
5
 
5
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
-
7
- var bs58__default = /*#__PURE__*/_interopDefault(bs58);
8
-
9
- // src/base58.ts
10
- function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
6
+ // src/key-pair.ts
7
+ async function generateKeyPair() {
8
+ await assertions.assertKeyGenerationIsAvailable();
9
+ const keyPair = await crypto.subtle.generateKey(
10
+ /* algorithm */
11
+ "Ed25519",
12
+ // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
13
+ /* extractable */
14
+ false,
15
+ // Prevents the bytes of the private key from being visible to JS.
16
+ /* allowed uses */
17
+ ["sign", "verify"]
18
+ );
19
+ return keyPair;
20
+ }
21
+ var base58Encoder;
22
+ function assertIsSignature(putativeSignature) {
23
+ if (!base58Encoder)
24
+ base58Encoder = codecsStrings.getBase58Encoder();
11
25
  try {
12
26
  if (
13
- // Lowest address (32 bytes of zeroes)
14
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
15
- putativeBase58EncodedAddress.length > 44
27
+ // Lowest value (64 bytes of zeroes)
28
+ putativeSignature.length < 64 || // Highest value (64 bytes of 255)
29
+ putativeSignature.length > 88
16
30
  ) {
17
- throw new Error("Expected input string to decode to a byte array of length 32.");
31
+ throw new Error("Expected input string to decode to a byte array of length 64.");
18
32
  }
19
- const bytes = bs58__default.default.decode(putativeBase58EncodedAddress);
33
+ const bytes = base58Encoder.encode(putativeSignature);
20
34
  const numBytes = bytes.byteLength;
21
- if (numBytes !== 32) {
22
- throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
35
+ if (numBytes !== 64) {
36
+ throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
23
37
  }
24
38
  } catch (e) {
25
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
39
+ throw new Error(`\`${putativeSignature}\` is not a signature`, {
26
40
  cause: e
27
41
  });
28
42
  }
29
43
  }
30
- function getBase58EncodedAddressComparator() {
31
- return new Intl.Collator("en", {
32
- caseFirst: "lower",
33
- ignorePunctuation: false,
34
- localeMatcher: "best fit",
35
- numeric: false,
36
- sensitivity: "variant",
37
- usage: "sort"
38
- }).compare;
44
+ function isSignature(putativeSignature) {
45
+ if (!base58Encoder)
46
+ base58Encoder = codecsStrings.getBase58Encoder();
47
+ if (
48
+ // Lowest value (64 bytes of zeroes)
49
+ putativeSignature.length < 64 || // Highest value (64 bytes of 255)
50
+ putativeSignature.length > 88
51
+ ) {
52
+ return false;
53
+ }
54
+ const bytes = base58Encoder.encode(putativeSignature);
55
+ const numBytes = bytes.byteLength;
56
+ if (numBytes !== 64) {
57
+ return false;
58
+ }
59
+ return true;
60
+ }
61
+ async function signBytes(key, data) {
62
+ await assertions.assertSigningCapabilityIsAvailable();
63
+ const signedData = await crypto.subtle.sign("Ed25519", key, data);
64
+ return new Uint8Array(signedData);
65
+ }
66
+ function signature(putativeSignature) {
67
+ assertIsSignature(putativeSignature);
68
+ return putativeSignature;
69
+ }
70
+ async function verifySignature(key, signature2, data) {
71
+ await assertions.assertVerificationCapabilityIsAvailable();
72
+ return await crypto.subtle.verify("Ed25519", key, signature2, data);
39
73
  }
40
74
 
41
- exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
42
- exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
75
+ exports.assertIsSignature = assertIsSignature;
76
+ exports.generateKeyPair = generateKeyPair;
77
+ exports.isSignature = isSignature;
78
+ exports.signBytes = signBytes;
79
+ exports.signature = signature;
80
+ exports.verifySignature = verifySignature;
43
81
  //# sourceMappingURL=out.js.map
44
82
  //# sourceMappingURL=index.node.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/base58.ts"],"names":[],"mappings":";AAAA,OAAO,UAAU;AAMV,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,KAAK,OAAO,4BAA4B;AACtD,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 bs58 from 'bs58';\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 = bs58.decode(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":["signature"],"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;AAE5F,SAAS,wBAAwB;AAKjC,IAAI;AAEG,SAAS,kBAAkB,mBAAmE;AACjG,MAAI,CAAC;AAAe,oBAAgB,iBAAiB;AAErD,MAAI;AAEA;AAAA;AAAA,MAEI,kBAAkB,SAAS;AAAA,MAE3B,kBAAkB,SAAS;AAAA,MAC7B;AACE,YAAM,IAAI,MAAM,+DAA+D;AAAA,IACnF;AAEA,UAAM,QAAQ,cAAc,OAAO,iBAAiB;AACpD,UAAM,WAAW,MAAM;AACvB,QAAI,aAAa,IAAI;AACjB,YAAM,IAAI,MAAM,gFAAgF,QAAQ,EAAE;AAAA,IAC9G;AAAA,EACJ,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,iBAAiB,yBAAyB;AAAA,MAC3D,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,YAAY,mBAA2D;AACnF,MAAI,CAAC;AAAe,oBAAgB,iBAAiB;AAGrD;AAAA;AAAA,IAEI,kBAAkB,SAAS;AAAA,IAE3B,kBAAkB,SAAS;AAAA,IAC7B;AACE,WAAO;AAAA,EACX;AAEA,QAAM,QAAQ,cAAc,OAAO,iBAAiB;AACpD,QAAM,WAAW,MAAM;AACvB,MAAI,aAAa,IAAI;AACjB,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAEA,eAAsB,UAAU,KAAgB,MAA2C;AACvF,QAAM,mCAAmC;AACzC,QAAM,aAAa,MAAM,OAAO,OAAO,KAAK,WAAW,KAAK,IAAI;AAChE,SAAO,IAAI,WAAW,UAAU;AACpC;AAEO,SAAS,UAAU,mBAAsC;AAC5D,oBAAkB,iBAAiB;AACnC,SAAO;AACX;AAEA,eAAsB,gBAAgB,KAAgBA,YAA2B,MAAoC;AACjH,QAAM,wCAAwC;AAC9C,SAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAKA,YAAW,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';\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,37 +1,75 @@
1
- import bs58 from 'bs58';
1
+ import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';
2
+ import { getBase58Encoder } from '@solana/codecs-strings';
2
3
 
3
- // src/base58.ts
4
- function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
4
+ // src/key-pair.ts
5
+ async function generateKeyPair() {
6
+ await assertKeyGenerationIsAvailable();
7
+ const keyPair = await crypto.subtle.generateKey(
8
+ /* algorithm */
9
+ "Ed25519",
10
+ // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
11
+ /* extractable */
12
+ false,
13
+ // Prevents the bytes of the private key from being visible to JS.
14
+ /* allowed uses */
15
+ ["sign", "verify"]
16
+ );
17
+ return keyPair;
18
+ }
19
+ var base58Encoder;
20
+ function assertIsSignature(putativeSignature) {
21
+ if (!base58Encoder)
22
+ base58Encoder = getBase58Encoder();
5
23
  try {
6
24
  if (
7
- // Lowest address (32 bytes of zeroes)
8
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
9
- putativeBase58EncodedAddress.length > 44
25
+ // Lowest value (64 bytes of zeroes)
26
+ putativeSignature.length < 64 || // Highest value (64 bytes of 255)
27
+ putativeSignature.length > 88
10
28
  ) {
11
- throw new Error("Expected input string to decode to a byte array of length 32.");
29
+ throw new Error("Expected input string to decode to a byte array of length 64.");
12
30
  }
13
- const bytes = bs58.decode(putativeBase58EncodedAddress);
31
+ const bytes = base58Encoder.encode(putativeSignature);
14
32
  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}`);
33
+ if (numBytes !== 64) {
34
+ throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
17
35
  }
18
36
  } catch (e) {
19
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
37
+ throw new Error(`\`${putativeSignature}\` is not a signature`, {
20
38
  cause: e
21
39
  });
22
40
  }
23
41
  }
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;
42
+ function isSignature(putativeSignature) {
43
+ if (!base58Encoder)
44
+ base58Encoder = getBase58Encoder();
45
+ if (
46
+ // Lowest value (64 bytes of zeroes)
47
+ putativeSignature.length < 64 || // Highest value (64 bytes of 255)
48
+ putativeSignature.length > 88
49
+ ) {
50
+ return false;
51
+ }
52
+ const bytes = base58Encoder.encode(putativeSignature);
53
+ const numBytes = bytes.byteLength;
54
+ if (numBytes !== 64) {
55
+ return false;
56
+ }
57
+ return true;
58
+ }
59
+ async function signBytes(key, data) {
60
+ await assertSigningCapabilityIsAvailable();
61
+ const signedData = await crypto.subtle.sign("Ed25519", key, data);
62
+ return new Uint8Array(signedData);
63
+ }
64
+ function signature(putativeSignature) {
65
+ assertIsSignature(putativeSignature);
66
+ return putativeSignature;
67
+ }
68
+ async function verifySignature(key, signature2, data) {
69
+ await assertVerificationCapabilityIsAvailable();
70
+ return await crypto.subtle.verify("Ed25519", key, signature2, data);
33
71
  }
34
72
 
35
- export { assertIsBase58EncodedAddress, getBase58EncodedAddressComparator };
73
+ export { assertIsSignature, generateKeyPair, isSignature, signBytes, signature, verifySignature };
36
74
  //# sourceMappingURL=out.js.map
37
75
  //# sourceMappingURL=index.node.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/base58.ts"],"names":[],"mappings":";AAAA,OAAO,UAAU;AAMV,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,KAAK,OAAO,4BAA4B;AACtD,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 bs58 from 'bs58';\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 = bs58.decode(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":["signature"],"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;AAE5F,SAAS,wBAAwB;AAKjC,IAAI;AAEG,SAAS,kBAAkB,mBAAmE;AACjG,MAAI,CAAC;AAAe,oBAAgB,iBAAiB;AAErD,MAAI;AAEA;AAAA;AAAA,MAEI,kBAAkB,SAAS;AAAA,MAE3B,kBAAkB,SAAS;AAAA,MAC7B;AACE,YAAM,IAAI,MAAM,+DAA+D;AAAA,IACnF;AAEA,UAAM,QAAQ,cAAc,OAAO,iBAAiB;AACpD,UAAM,WAAW,MAAM;AACvB,QAAI,aAAa,IAAI;AACjB,YAAM,IAAI,MAAM,gFAAgF,QAAQ,EAAE;AAAA,IAC9G;AAAA,EACJ,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,iBAAiB,yBAAyB;AAAA,MAC3D,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,YAAY,mBAA2D;AACnF,MAAI,CAAC;AAAe,oBAAgB,iBAAiB;AAGrD;AAAA;AAAA,IAEI,kBAAkB,SAAS;AAAA,IAE3B,kBAAkB,SAAS;AAAA,IAC7B;AACE,WAAO;AAAA,EACX;AAEA,QAAM,QAAQ,cAAc,OAAO,iBAAiB;AACpD,QAAM,WAAW,MAAM;AACvB,MAAI,aAAa,IAAI;AACjB,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAEA,eAAsB,UAAU,KAAgB,MAA2C;AACvF,QAAM,mCAAmC;AACzC,QAAM,aAAa,MAAM,OAAO,OAAO,KAAK,WAAW,KAAK,IAAI;AAChE,SAAO,IAAI,WAAW,UAAU;AACpC;AAEO,SAAS,UAAU,mBAAsC;AAC5D,oBAAkB,iBAAiB;AACnC,SAAO;AACX;AAEA,eAAsB,gBAAgB,KAAgBA,YAA2B,MAAoC;AACjH,QAAM,wCAAwC;AAC9C,SAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAKA,YAAW,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';\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"]}
@@ -2,10 +2,18 @@ this.globalThis = this.globalThis || {};
2
2
  this.globalThis.solanaWeb3 = (function (exports) {
3
3
  'use strict';
4
4
 
5
- var O=Object.create;var x=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var I=(e,r)=>()=>(e&&(r=e(e=0)),r);var U=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var $=(e,r,n,p)=>{if(r&&typeof r=="object"||typeof r=="function")for(let v of S(r))!q.call(e,v)&&v!==n&&x(e,v,{get:()=>r[v],enumerable:!(p=R(r,v))||p.enumerable});return e};var k=(e,r,n)=>(n=e!=null?O(V(e)):{},$(r||!e||!e.__esModule?x(n,"default",{value:e,enumerable:!0}):n,e));var g=I(()=>{});var _=U((X,z)=>{g();function G(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var p=0;p<e.length;p++){var v=e.charAt(p),E=v.charCodeAt(0);if(r[E]!==255)throw new TypeError(v+" is ambiguous");r[E]=p;}var A=e.length,u=e.charAt(0),T=Math.log(A)/Math.log(256),B=Math.log(256)/Math.log(A);function D(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(t.length===0)return "";for(var a=0,y=0,s=0,d=t.length;s!==d&&t[s]===0;)s++,a++;for(var f=(d-s)*B+1>>>0,o=new Uint8Array(f);s!==d;){for(var h=t[s],w=0,i=f-1;(h!==0||w<y)&&i!==-1;i--,w++)h+=256*o[i]>>>0,o[i]=h%A>>>0,h=h/A>>>0;if(h!==0)throw new Error("Non-zero carry");y=w,s++;}for(var l=f-y;l!==f&&o[l]===0;)l++;for(var b=u.repeat(a);l<f;++l)b+=e.charAt(o[l]);return b}function m(t){if(typeof t!="string")throw new TypeError("Expected String");if(t.length===0)return new Uint8Array;for(var a=0,y=0,s=0;t[a]===u;)y++,a++;for(var d=(t.length-a)*T+1>>>0,f=new Uint8Array(d);t[a];){var o=r[t.charCodeAt(a)];if(o===255)return;for(var h=0,w=d-1;(o!==0||h<s)&&w!==-1;w--,h++)o+=A*f[w]>>>0,f[w]=o%256>>>0,o=o/256>>>0;if(o!==0)throw new Error("Non-zero carry");s=h,a++;}for(var i=d-s;i!==d&&f[i]===0;)i++;for(var l=new Uint8Array(y+(d-i)),b=y;i!==d;)l[b++]=f[i++];return l}function F(t){var a=m(t);if(a)return a;throw new Error("Non-base"+A+" character")}return {encode:D,decodeUnsafe:m,decode:F}}z.exports=G;});var M=U((Z,C)=>{g();var J=_(),K="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";C.exports=J(K);});g();g();var N=k(M(),1);function L(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 n=N.default.decode(e).byteLength;if(n!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${n}`)}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 u(){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 r;async function v(e){return r===void 0&&(r=new Promise(t=>{e.generateKey("Ed25519",!1,["sign","verify"]).catch(()=>{t(r=!1);}).then(()=>{t(r=!0);});})),typeof r=="boolean"?r:await r}async function b(){var e;if(u(),typeof globalThis.crypto>"u"||typeof((e=globalThis.crypto.subtle)==null?void 0:e.generateKey)!="function")throw new Error("No key generation implementation could be found");if(!await v(globalThis.crypto.subtle))throw new Error(`This runtime does not support the generation of Ed25519 key pairs.
6
6
 
7
- exports.assertIsBase58EncodedAddress = L;
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 m(){var e;if(u(),typeof globalThis.crypto>"u"||typeof((e=globalThis.crypto.subtle)==null?void 0:e.sign)!="function")throw new Error("No signing implementation could be found")}async function x(){var e;if(u(),typeof globalThis.crypto>"u"||typeof((e=globalThis.crypto.subtle)==null?void 0:e.verify)!="function")throw new Error("No signature verification implementation could be found")}async function D(){return await b(),await crypto.subtle.generateKey("Ed25519",!1,["sign","verify"])}function E(e,t,n=t){if(!t.match(new RegExp(`^[${e}]*$`)))throw new Error(`Expected a string of base ${e.length}, got [${n}].`)}var S=e=>{let t=e.length,n=BigInt(t);return {description:`base${t}`,encode(d){if(E(e,d),d==="")return new Uint8Array;let a=[...d],o=a.findIndex(s=>s!==e[0]);o=o===-1?a.length:o;let f=Array(o).fill(0);if(o===a.length)return Uint8Array.from(f);let y=a.slice(o),c=0n,p=1n;for(let s=y.length-1;s>=0;s-=1)c+=p*BigInt(e.indexOf(y[s])),p*=n;let h=[];for(;c>0n;)h.unshift(Number(c%256n)),c/=256n;return Uint8Array.from(f.concat(h))},fixedSize:null,maxSize:null}};var w="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",g=()=>S(w);var i;function C(e){i||(i=g());try{if(e.length<64||e.length>88)throw new Error("Expected input string to decode to a byte array of length 64.");let n=i.encode(e).byteLength;if(n!==64)throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${n}`)}catch(t){throw new Error(`\`${e}\` is not a signature`,{cause:t})}}function X(e){return i||(i=g()),!(e.length<64||e.length>88||i.encode(e).byteLength!==64)}async function R(e,t){await m();let n=await crypto.subtle.sign("Ed25519",e,t);return new Uint8Array(n)}function V(e){return C(e),e}async function O(e,t,n){return await x(),await crypto.subtle.verify("Ed25519",e,t,n)}
10
+
11
+ exports.assertIsSignature = C;
12
+ exports.generateKeyPair = D;
13
+ exports.isSignature = X;
14
+ exports.signBytes = R;
15
+ exports.signature = V;
16
+ exports.verifySignature = O;
9
17
 
10
18
  return exports;
11
19
 
@@ -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,12 @@
1
+ export type Signature = string & {
2
+ readonly __brand: unique symbol;
3
+ };
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>;
12
+ //# 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.eefafdf",
3
+ "version": "2.0.0-experimental.ef09aec",
4
4
  "description": "Helpers for generating and transforming key material",
5
5
  "exports": {
6
6
  "browser": {
@@ -45,27 +45,31 @@
45
45
  "supports bigint and not dead",
46
46
  "maintained node versions"
47
47
  ],
48
+ "engine": {
49
+ "node": ">=17.4"
50
+ },
51
+ "dependencies": {
52
+ "@solana/assertions": "2.0.0-experimental.ef09aec",
53
+ "@solana/codecs-core": "2.0.0-experimental.ef09aec",
54
+ "@solana/codecs-strings": "2.0.0-experimental.ef09aec"
55
+ },
48
56
  "devDependencies": {
49
- "@solana/eslint-config-solana": "^1.0.1",
50
- "@swc/core": "^1.3.18",
51
- "@swc/jest": "^0.2.26",
52
- "@types/jest": "^29.5.1",
53
- "@typescript-eslint/eslint-plugin": "^5.57.1",
54
- "@typescript-eslint/parser": "^5.57.1",
57
+ "@solana/eslint-config-solana": "^1.0.2",
58
+ "@swc/jest": "^0.2.29",
59
+ "@types/jest": "^29.5.6",
60
+ "@typescript-eslint/eslint-plugin": "^6.7.0",
61
+ "@typescript-eslint/parser": "^6.3.0",
55
62
  "agadoo": "^3.0.0",
56
- "eslint": "^8.37.0",
57
- "eslint-plugin-jest": "^27.1.5",
58
- "eslint-plugin-react-hooks": "^4.6.0",
63
+ "eslint": "^8.45.0",
64
+ "eslint-plugin-jest": "^27.4.2",
59
65
  "eslint-plugin-sort-keys-fix": "^1.1.2",
60
- "jest": "^29.5.0",
61
- "jest-environment-jsdom": "^29.5.0",
62
- "jest-runner-eslint": "^2.1.0",
66
+ "jest": "^29.7.0",
67
+ "jest-environment-jsdom": "^29.7.0",
68
+ "jest-runner-eslint": "^2.1.2",
63
69
  "jest-runner-prettier": "^1.0.0",
64
- "postcss": "^8.4.12",
65
- "prettier": "^2.8.8",
66
- "ts-node": "^10.9.1",
67
- "tsup": "6.7.0",
68
- "typescript": "^5.0.4",
70
+ "prettier": "^2.8",
71
+ "tsup": "^8.0.1",
72
+ "typescript": "^5.2.2",
69
73
  "version-from-git": "^1.1.1",
70
74
  "build-scripts": "0.0.0",
71
75
  "test-config": "0.0.0",
@@ -79,19 +83,17 @@
79
83
  }
80
84
  ]
81
85
  },
82
- "dependencies": {
83
- "bs58": "^5.0.0"
84
- },
85
86
  "scripts": {
86
87
  "compile:js": "tsup --config build-scripts/tsup.config.library.ts",
87
88
  "compile:typedefs": "tsc -p ./tsconfig.declarations.json",
88
89
  "dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
89
90
  "publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
91
+ "style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
90
92
  "test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
91
93
  "test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
92
94
  "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",
95
+ "test:treeshakability:native": "agadoo dist/index.native.js",
96
+ "test:treeshakability:node": "agadoo dist/index.node.js",
95
97
  "test:typecheck": "tsc --noEmit",
96
98
  "test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",
97
99
  "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