@solana/keys 2.0.0-experimental.4199b4e → 2.0.0-experimental.433f475
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -2
- package/dist/index.browser.cjs +50 -2
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +48 -3
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +91 -2
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +48 -3
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +50 -2
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +48 -3
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +8 -5
- package/dist/types/signatures.d.ts +9 -3
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -18,7 +18,11 @@ This package contains utilities for validating, generating, and manipulating add
|
|
|
18
18
|
|
|
19
19
|
## Types
|
|
20
20
|
|
|
21
|
-
### `
|
|
21
|
+
### `Signature`
|
|
22
|
+
|
|
23
|
+
This type represents a 64-byte Ed25519 signature of some data with a private key, as a base58-encoded string.
|
|
24
|
+
|
|
25
|
+
### `SignatureBytes`
|
|
22
26
|
|
|
23
27
|
This type represents a 64-byte Ed25519 signature of some data with a private key.
|
|
24
28
|
|
|
@@ -26,6 +30,31 @@ Whenever you need to verify that a particular signature is, in fact, the one tha
|
|
|
26
30
|
|
|
27
31
|
## Functions
|
|
28
32
|
|
|
33
|
+
### `assertIsSignature()`
|
|
34
|
+
|
|
35
|
+
From time to time you might acquire a string that you expect to be a base58-encoded signature (eg. of a transaction) from an untrusted network API or user input. To assert that such an arbitrary string is in fact an Ed25519 signature, use the `assertIsSignature` function.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { assertIsSignature } from '@solana/keys';
|
|
39
|
+
|
|
40
|
+
// Imagine a function that asserts whether a user-supplied signature is valid or not.
|
|
41
|
+
function handleSubmit() {
|
|
42
|
+
// We know only that what the user typed conforms to the `string` type.
|
|
43
|
+
const signature: string = signatureInput.value;
|
|
44
|
+
try {
|
|
45
|
+
// If this type assertion function doesn't throw, then
|
|
46
|
+
// Typescript will upcast `signature` to `Signature`.
|
|
47
|
+
assertIsSignature(signature);
|
|
48
|
+
// At this point, `signature` is a `Signature` that can be used with the RPC.
|
|
49
|
+
const {
|
|
50
|
+
value: [status],
|
|
51
|
+
} = await rpc.getSignatureStatuses([signature]).send();
|
|
52
|
+
} catch (e) {
|
|
53
|
+
// `signature` turned out not to be a base58-encoded signature
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
29
58
|
### `generateKeyPair()`
|
|
30
59
|
|
|
31
60
|
Generates an Ed25519 public/private key pair for use with other methods in this package that accept `CryptoKey` objects.
|
|
@@ -36,6 +65,25 @@ import { generateKeyPair } from '@solana/keys';
|
|
|
36
65
|
const { privateKey, publicKey } = await generateKeyPair();
|
|
37
66
|
```
|
|
38
67
|
|
|
68
|
+
### `isSignature()`
|
|
69
|
+
|
|
70
|
+
This is a type guard that accepts a string as input. It will both return `true` if the string conforms to the `Signature` type and will refine the type for use in your program.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { isSignature } from '@solana/keys';
|
|
74
|
+
|
|
75
|
+
if (isSignature(signature)) {
|
|
76
|
+
// At this point, `signature` has been refined to a
|
|
77
|
+
// `Signature` that can be used with the RPC.
|
|
78
|
+
const {
|
|
79
|
+
value: [status],
|
|
80
|
+
} = await rpc.getSignatureStatuses([signature]).send();
|
|
81
|
+
setSignatureStatus(status);
|
|
82
|
+
} else {
|
|
83
|
+
setError(`${signature} is not a transaction signature`);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
39
87
|
### `signBytes()`
|
|
40
88
|
|
|
41
89
|
Given a private `CryptoKey` and a `Uint8Array` of bytes, this method will return the 64-byte Ed25519 signature of that data as a `Uint8Array`.
|
|
@@ -47,9 +95,22 @@ const data = new Uint8Array([1, 2, 3]);
|
|
|
47
95
|
const signature = await signBytes(privateKey, data);
|
|
48
96
|
```
|
|
49
97
|
|
|
98
|
+
### `signature()`
|
|
99
|
+
|
|
100
|
+
This helper combines _asserting_ that a string is an Ed25519 signature with _coercing_ it to the `Signature` type. It's best used with untrusted input.
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { signature } from '@solana/keys';
|
|
104
|
+
|
|
105
|
+
const signature = signature(userSuppliedSignature);
|
|
106
|
+
const {
|
|
107
|
+
value: [status],
|
|
108
|
+
} = await rpc.getSignatureStatuses([signature]).send();
|
|
109
|
+
```
|
|
110
|
+
|
|
50
111
|
### `verifySignature()`
|
|
51
112
|
|
|
52
|
-
Given a public `CryptoKey`,
|
|
113
|
+
Given a public `CryptoKey`, some `SignatureBytes`, and a `Uint8Array` of data, this method will return `true` if the signature was produced by signing the data using the private key associated with the public key, and `false` otherwise.
|
|
53
114
|
|
|
54
115
|
```ts
|
|
55
116
|
import { verifySignature } from '@solana/keys';
|
package/dist/index.browser.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var assertions = require('@solana/assertions');
|
|
4
|
+
var codecsStrings = require('@solana/codecs-strings');
|
|
4
5
|
|
|
5
6
|
// src/key-pair.ts
|
|
6
7
|
async function generateKeyPair() {
|
|
@@ -17,18 +18,65 @@ async function generateKeyPair() {
|
|
|
17
18
|
);
|
|
18
19
|
return keyPair;
|
|
19
20
|
}
|
|
21
|
+
var base58Encoder;
|
|
22
|
+
function assertIsSignature(putativeSignature) {
|
|
23
|
+
if (!base58Encoder)
|
|
24
|
+
base58Encoder = codecsStrings.getBase58Encoder();
|
|
25
|
+
try {
|
|
26
|
+
if (
|
|
27
|
+
// Lowest value (64 bytes of zeroes)
|
|
28
|
+
putativeSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
29
|
+
putativeSignature.length > 88
|
|
30
|
+
) {
|
|
31
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
32
|
+
}
|
|
33
|
+
const bytes = base58Encoder.encode(putativeSignature);
|
|
34
|
+
const numBytes = bytes.byteLength;
|
|
35
|
+
if (numBytes !== 64) {
|
|
36
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
37
|
+
}
|
|
38
|
+
} catch (e) {
|
|
39
|
+
throw new Error(`\`${putativeSignature}\` is not a signature`, {
|
|
40
|
+
cause: e
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
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
|
+
}
|
|
20
61
|
async function signBytes(key, data) {
|
|
21
62
|
await assertions.assertSigningCapabilityIsAvailable();
|
|
22
63
|
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
23
64
|
return new Uint8Array(signedData);
|
|
24
65
|
}
|
|
25
|
-
|
|
66
|
+
function signature(putativeSignature) {
|
|
67
|
+
assertIsSignature(putativeSignature);
|
|
68
|
+
return putativeSignature;
|
|
69
|
+
}
|
|
70
|
+
async function verifySignature(key, signature2, data) {
|
|
26
71
|
await assertions.assertVerificationCapabilityIsAvailable();
|
|
27
|
-
return await crypto.subtle.verify("Ed25519", key,
|
|
72
|
+
return await crypto.subtle.verify("Ed25519", key, signature2, data);
|
|
28
73
|
}
|
|
29
74
|
|
|
75
|
+
exports.assertIsSignature = assertIsSignature;
|
|
30
76
|
exports.generateKeyPair = generateKeyPair;
|
|
77
|
+
exports.isSignature = isSignature;
|
|
31
78
|
exports.signBytes = signBytes;
|
|
79
|
+
exports.signature = signature;
|
|
32
80
|
exports.verifySignature = verifySignature;
|
|
33
81
|
//# sourceMappingURL=out.js.map
|
|
34
82
|
//# sourceMappingURL=index.browser.cjs.map
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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"]}
|
package/dist/index.browser.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';
|
|
2
|
+
import { getBase58Encoder } from '@solana/codecs-strings';
|
|
2
3
|
|
|
3
4
|
// src/key-pair.ts
|
|
4
5
|
async function generateKeyPair() {
|
|
@@ -15,16 +16,60 @@ async function generateKeyPair() {
|
|
|
15
16
|
);
|
|
16
17
|
return keyPair;
|
|
17
18
|
}
|
|
19
|
+
var base58Encoder;
|
|
20
|
+
function assertIsSignature(putativeSignature) {
|
|
21
|
+
if (!base58Encoder)
|
|
22
|
+
base58Encoder = getBase58Encoder();
|
|
23
|
+
try {
|
|
24
|
+
if (
|
|
25
|
+
// Lowest value (64 bytes of zeroes)
|
|
26
|
+
putativeSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
27
|
+
putativeSignature.length > 88
|
|
28
|
+
) {
|
|
29
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
30
|
+
}
|
|
31
|
+
const bytes = base58Encoder.encode(putativeSignature);
|
|
32
|
+
const numBytes = bytes.byteLength;
|
|
33
|
+
if (numBytes !== 64) {
|
|
34
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
throw new Error(`\`${putativeSignature}\` is not a signature`, {
|
|
38
|
+
cause: e
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
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
|
+
}
|
|
18
59
|
async function signBytes(key, data) {
|
|
19
60
|
await assertSigningCapabilityIsAvailable();
|
|
20
61
|
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
21
62
|
return new Uint8Array(signedData);
|
|
22
63
|
}
|
|
23
|
-
|
|
64
|
+
function signature(putativeSignature) {
|
|
65
|
+
assertIsSignature(putativeSignature);
|
|
66
|
+
return putativeSignature;
|
|
67
|
+
}
|
|
68
|
+
async function verifySignature(key, signature2, data) {
|
|
24
69
|
await assertVerificationCapabilityIsAvailable();
|
|
25
|
-
return await crypto.subtle.verify("Ed25519", key,
|
|
70
|
+
return await crypto.subtle.verify("Ed25519", key, signature2, data);
|
|
26
71
|
}
|
|
27
72
|
|
|
28
|
-
export { generateKeyPair, signBytes, verifySignature };
|
|
73
|
+
export { assertIsSignature, generateKeyPair, isSignature, signBytes, signature, verifySignature };
|
|
29
74
|
//# sourceMappingURL=out.js.map
|
|
30
75
|
//# sourceMappingURL=index.browser.js.map
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AA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AO,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"]}
|
|
@@ -72,19 +72,108 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
72
72
|
return keyPair;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
// ../codecs-strings/dist/index.browser.js
|
|
76
|
+
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
77
|
+
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
78
|
+
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
var getBaseXEncoder = (alphabet4) => {
|
|
82
|
+
const base = alphabet4.length;
|
|
83
|
+
const baseBigInt = BigInt(base);
|
|
84
|
+
return {
|
|
85
|
+
description: `base${base}`,
|
|
86
|
+
encode(value) {
|
|
87
|
+
assertValidBaseString(alphabet4, value);
|
|
88
|
+
if (value === "")
|
|
89
|
+
return new Uint8Array();
|
|
90
|
+
const chars = [...value];
|
|
91
|
+
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
|
|
92
|
+
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
93
|
+
const leadingZeroes = Array(trailIndex).fill(0);
|
|
94
|
+
if (trailIndex === chars.length)
|
|
95
|
+
return Uint8Array.from(leadingZeroes);
|
|
96
|
+
const tailChars = chars.slice(trailIndex);
|
|
97
|
+
let base10Number = 0n;
|
|
98
|
+
let baseXPower = 1n;
|
|
99
|
+
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
100
|
+
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
|
|
101
|
+
baseXPower *= baseBigInt;
|
|
102
|
+
}
|
|
103
|
+
const tailBytes = [];
|
|
104
|
+
while (base10Number > 0n) {
|
|
105
|
+
tailBytes.unshift(Number(base10Number % 256n));
|
|
106
|
+
base10Number /= 256n;
|
|
107
|
+
}
|
|
108
|
+
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
109
|
+
},
|
|
110
|
+
fixedSize: null,
|
|
111
|
+
maxSize: null
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
115
|
+
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
116
|
+
|
|
75
117
|
// src/signatures.ts
|
|
118
|
+
var base58Encoder;
|
|
119
|
+
function assertIsSignature(putativeSignature) {
|
|
120
|
+
if (!base58Encoder)
|
|
121
|
+
base58Encoder = getBase58Encoder();
|
|
122
|
+
try {
|
|
123
|
+
if (
|
|
124
|
+
// Lowest value (64 bytes of zeroes)
|
|
125
|
+
putativeSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
126
|
+
putativeSignature.length > 88
|
|
127
|
+
) {
|
|
128
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
129
|
+
}
|
|
130
|
+
const bytes = base58Encoder.encode(putativeSignature);
|
|
131
|
+
const numBytes = bytes.byteLength;
|
|
132
|
+
if (numBytes !== 64) {
|
|
133
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
134
|
+
}
|
|
135
|
+
} catch (e2) {
|
|
136
|
+
throw new Error(`\`${putativeSignature}\` is not a signature`, {
|
|
137
|
+
cause: e2
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function isSignature(putativeSignature) {
|
|
142
|
+
if (!base58Encoder)
|
|
143
|
+
base58Encoder = getBase58Encoder();
|
|
144
|
+
if (
|
|
145
|
+
// Lowest value (64 bytes of zeroes)
|
|
146
|
+
putativeSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
147
|
+
putativeSignature.length > 88
|
|
148
|
+
) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
const bytes = base58Encoder.encode(putativeSignature);
|
|
152
|
+
const numBytes = bytes.byteLength;
|
|
153
|
+
if (numBytes !== 64) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
76
158
|
async function signBytes(key, data) {
|
|
77
159
|
await assertSigningCapabilityIsAvailable();
|
|
78
160
|
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
79
161
|
return new Uint8Array(signedData);
|
|
80
162
|
}
|
|
81
|
-
|
|
163
|
+
function signature(putativeSignature) {
|
|
164
|
+
assertIsSignature(putativeSignature);
|
|
165
|
+
return putativeSignature;
|
|
166
|
+
}
|
|
167
|
+
async function verifySignature(key, signature2, data) {
|
|
82
168
|
await assertVerificationCapabilityIsAvailable();
|
|
83
|
-
return await crypto.subtle.verify("Ed25519", key,
|
|
169
|
+
return await crypto.subtle.verify("Ed25519", key, signature2, data);
|
|
84
170
|
}
|
|
85
171
|
|
|
172
|
+
exports.assertIsSignature = assertIsSignature;
|
|
86
173
|
exports.generateKeyPair = generateKeyPair;
|
|
174
|
+
exports.isSignature = isSignature;
|
|
87
175
|
exports.signBytes = signBytes;
|
|
176
|
+
exports.signature = signature;
|
|
88
177
|
exports.verifySignature = verifySignature;
|
|
89
178
|
|
|
90
179
|
return exports;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../assertions/src/subtle-crypto.ts","../src/key-pair.ts","../src/signatures.ts"],"names":[],"mappings":";AAAA,SAAS,wBAAwB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,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
|
+
{"version":3,"sources":["../../assertions/src/subtle-crypto.ts","../src/key-pair.ts","../../codecs-strings/src/assertions.ts","../../codecs-strings/src/baseX.ts","../../codecs-strings/src/base16.ts","../../codecs-strings/src/base64.ts","../src/signatures.ts"],"names":["alphabet","e","signature"],"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;AAC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.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","/**\n * Asserts that a given string matches a given alphabet.\n */\nexport function assertValidBaseString(alphabet: string, testValue: string, givenValue = testValue) {\n if (!testValue.match(new RegExp(`^[${alphabet}]*$`))) {\n // TODO: Coded error.\n throw new Error(`Expected a string of base ${alphabet.length}, got [${givenValue}].`);\n }\n}\n","import { Codec, combineCodec, Decoder, Encoder } from '@solana/codecs-core';\n\nimport { assertValidBaseString } from './assertions';\n\n/**\n * Encodes a string using a custom alphabet by dividing\n * by the base and handling leading zeroes.\n * @see {@link getBaseXCodec} for a more detailed description.\n */\nexport const getBaseXEncoder = (alphabet: string): Encoder<string> => {\n const base = alphabet.length;\n const baseBigInt = BigInt(base);\n return {\n description: `base${base}`,\n encode(value: string): Uint8Array {\n // Check if the value is valid.\n assertValidBaseString(alphabet, value);\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 fixedSize: null,\n maxSize: null,\n };\n};\n\n/**\n * Decodes a string using a custom alphabet by dividing\n * by the base and handling leading zeroes.\n * @see {@link getBaseXCodec} for a more detailed description.\n */\nexport const getBaseXDecoder = (alphabet: string): Decoder<string> => {\n const base = alphabet.length;\n const baseBigInt = BigInt(base);\n return {\n decode(rawBytes, offset = 0): [string, number] {\n const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);\n if (bytes.length === 0) return ['', 0];\n\n // Handle leading zeroes.\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, rawBytes.length];\n\n // From bytes to base10.\n let base10Number = bytes.slice(trailIndex).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(''), rawBytes.length];\n },\n description: `base${base}`,\n fixedSize: null,\n maxSize: null,\n };\n};\n\n/**\n * A string codec that requires a custom alphabet and uses\n * the length of that alphabet as the base. It then divides\n * the input by the base as many times as necessary to get\n * the output. It also supports leading zeroes by using the\n * first character of the alphabet as the zero character.\n *\n * This can be used to create codecs such as base10 or base58.\n */\nexport const getBaseXCodec = (alphabet: string): Codec<string> =>\n combineCodec(getBaseXEncoder(alphabet), getBaseXDecoder(alphabet));\n","import { Codec, combineCodec, Decoder, Encoder } from '@solana/codecs-core';\n\nimport { assertValidBaseString } from './assertions';\n\n/** Encodes strings in base16. */\nexport const getBase16Encoder = (): Encoder<string> => ({\n description: 'base16',\n encode(value: string) {\n const lowercaseValue = value.toLowerCase();\n assertValidBaseString('0123456789abcdef', lowercaseValue, value);\n const matches = lowercaseValue.match(/.{1,2}/g);\n return Uint8Array.from(matches ? matches.map((byte: string) => parseInt(byte, 16)) : []);\n },\n fixedSize: null,\n maxSize: null,\n});\n\n/** Decodes strings in base16. */\nexport const getBase16Decoder = (): Decoder<string> => ({\n decode(bytes, offset = 0) {\n const value = bytes.slice(offset).reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');\n return [value, bytes.length];\n },\n description: 'base16',\n fixedSize: null,\n maxSize: null,\n});\n\n/** Encodes and decodes strings in base16. */\nexport const getBase16Codec = (): Codec<string> => combineCodec(getBase16Encoder(), getBase16Decoder());\n","import { combineCodec, Decoder, Encoder, mapDecoder, mapEncoder } from '@solana/codecs-core';\n\nimport { assertValidBaseString } from './assertions';\nimport { getBaseXResliceDecoder, getBaseXResliceEncoder } from './baseX-reslice';\n\nconst alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\n/** Encodes strings in base64. */\nexport const getBase64Encoder = (): Encoder<string> => {\n if (__BROWSER__) {\n return {\n description: `base64`,\n encode(value: string): Uint8Array {\n try {\n const bytes = (atob as Window['atob'])(value)\n .split('')\n .map(c => c.charCodeAt(0));\n return new Uint8Array(bytes);\n } catch (e) {\n // TODO: Coded error.\n throw new Error(`Expected a string of base 64, got [${value}].`);\n }\n },\n fixedSize: null,\n maxSize: null,\n };\n }\n\n if (__NODEJS__) {\n return {\n description: `base64`,\n encode(value: string): Uint8Array {\n assertValidBaseString(alphabet, value.replace(/=/g, ''));\n return new Uint8Array(Buffer.from(value, 'base64'));\n },\n fixedSize: null,\n maxSize: null,\n };\n }\n\n return mapEncoder(getBaseXResliceEncoder(alphabet, 6), (value: string): string => value.replace(/=/g, ''));\n};\n\n/** Decodes strings in base64. */\nexport const getBase64Decoder = (): Decoder<string> => {\n if (__BROWSER__) {\n return {\n decode(bytes, offset = 0) {\n const slice = bytes.slice(offset);\n const value = (btoa as Window['btoa'])(String.fromCharCode(...slice));\n return [value, bytes.length];\n },\n description: `base64`,\n fixedSize: null,\n maxSize: null,\n };\n }\n\n if (__NODEJS__) {\n return {\n decode: (bytes, offset = 0) => [Buffer.from(bytes, offset).toString('base64'), bytes.length],\n description: `base64`,\n fixedSize: null,\n maxSize: null,\n };\n }\n\n return mapDecoder(getBaseXResliceDecoder(alphabet, 6), (value: string): string =>\n value.padEnd(Math.ceil(value.length / 4) * 4, '=')\n );\n};\n\n/** Encodes and decodes strings in base64. */\nexport const getBase64Codec = () => combineCodec(getBase64Encoder(), getBase64Decoder());\n","import { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\nimport { Encoder } from '@solana/codecs-core';\nimport { getBase58Encoder } from '@solana/codecs-strings';\n\nexport type Signature = string & { readonly __brand: unique symbol };\nexport type SignatureBytes = Uint8Array & { readonly __brand: unique symbol };\n\nlet base58Encoder: Encoder<string> | undefined;\n\nexport function assertIsSignature(putativeSignature: string): asserts putativeSignature is Signature {\n if (!base58Encoder) base58Encoder = getBase58Encoder();\n\n try {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest value (64 bytes of zeroes)\n putativeSignature.length < 64 ||\n // Highest value (64 bytes of 255)\n putativeSignature.length > 88\n ) {\n throw new Error('Expected input string to decode to a byte array of length 64.');\n }\n // Slow-path; actually attempt to decode the input string.\n const bytes = base58Encoder.encode(putativeSignature);\n const numBytes = bytes.byteLength;\n if (numBytes !== 64) {\n throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);\n }\n } catch (e) {\n throw new Error(`\\`${putativeSignature}\\` is not a signature`, {\n cause: e,\n });\n }\n}\n\nexport function isSignature(putativeSignature: string): putativeSignature is Signature {\n if (!base58Encoder) base58Encoder = getBase58Encoder();\n\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest value (64 bytes of zeroes)\n putativeSignature.length < 64 ||\n // Highest value (64 bytes of 255)\n putativeSignature.length > 88\n ) {\n return false;\n }\n // Slow-path; actually attempt to decode the input string.\n const bytes = base58Encoder.encode(putativeSignature);\n const numBytes = bytes.byteLength;\n if (numBytes !== 64) {\n return false;\n }\n return true;\n}\n\nexport async function signBytes(key: CryptoKey, data: Uint8Array): Promise<SignatureBytes> {\n await assertSigningCapabilityIsAvailable();\n const signedData = await crypto.subtle.sign('Ed25519', key, data);\n return new Uint8Array(signedData) as SignatureBytes;\n}\n\nexport function signature(putativeSignature: string): Signature {\n assertIsSignature(putativeSignature);\n return putativeSignature;\n}\n\nexport async function verifySignature(key: CryptoKey, signature: SignatureBytes, data: Uint8Array): Promise<boolean> {\n await assertVerificationCapabilityIsAvailable();\n return await crypto.subtle.verify('Ed25519', key, signature, data);\n}\n"]}
|
package/dist/index.native.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';
|
|
2
|
+
import { getBase58Encoder } from '@solana/codecs-strings';
|
|
2
3
|
|
|
3
4
|
// src/key-pair.ts
|
|
4
5
|
async function generateKeyPair() {
|
|
@@ -15,16 +16,60 @@ async function generateKeyPair() {
|
|
|
15
16
|
);
|
|
16
17
|
return keyPair;
|
|
17
18
|
}
|
|
19
|
+
var base58Encoder;
|
|
20
|
+
function assertIsSignature(putativeSignature) {
|
|
21
|
+
if (!base58Encoder)
|
|
22
|
+
base58Encoder = getBase58Encoder();
|
|
23
|
+
try {
|
|
24
|
+
if (
|
|
25
|
+
// Lowest value (64 bytes of zeroes)
|
|
26
|
+
putativeSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
27
|
+
putativeSignature.length > 88
|
|
28
|
+
) {
|
|
29
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
30
|
+
}
|
|
31
|
+
const bytes = base58Encoder.encode(putativeSignature);
|
|
32
|
+
const numBytes = bytes.byteLength;
|
|
33
|
+
if (numBytes !== 64) {
|
|
34
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
throw new Error(`\`${putativeSignature}\` is not a signature`, {
|
|
38
|
+
cause: e
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
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
|
+
}
|
|
18
59
|
async function signBytes(key, data) {
|
|
19
60
|
await assertSigningCapabilityIsAvailable();
|
|
20
61
|
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
21
62
|
return new Uint8Array(signedData);
|
|
22
63
|
}
|
|
23
|
-
|
|
64
|
+
function signature(putativeSignature) {
|
|
65
|
+
assertIsSignature(putativeSignature);
|
|
66
|
+
return putativeSignature;
|
|
67
|
+
}
|
|
68
|
+
async function verifySignature(key, signature2, data) {
|
|
24
69
|
await assertVerificationCapabilityIsAvailable();
|
|
25
|
-
return await crypto.subtle.verify("Ed25519", key,
|
|
70
|
+
return await crypto.subtle.verify("Ed25519", key, signature2, data);
|
|
26
71
|
}
|
|
27
72
|
|
|
28
|
-
export { generateKeyPair, signBytes, verifySignature };
|
|
73
|
+
export { assertIsSignature, generateKeyPair, isSignature, signBytes, signature, verifySignature };
|
|
29
74
|
//# sourceMappingURL=out.js.map
|
|
30
75
|
//# sourceMappingURL=index.native.js.map
|
package/dist/index.native.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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"]}
|
package/dist/index.node.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var assertions = require('@solana/assertions');
|
|
4
|
+
var codecsStrings = require('@solana/codecs-strings');
|
|
4
5
|
|
|
5
6
|
// src/key-pair.ts
|
|
6
7
|
async function generateKeyPair() {
|
|
@@ -17,18 +18,65 @@ async function generateKeyPair() {
|
|
|
17
18
|
);
|
|
18
19
|
return keyPair;
|
|
19
20
|
}
|
|
21
|
+
var base58Encoder;
|
|
22
|
+
function assertIsSignature(putativeSignature) {
|
|
23
|
+
if (!base58Encoder)
|
|
24
|
+
base58Encoder = codecsStrings.getBase58Encoder();
|
|
25
|
+
try {
|
|
26
|
+
if (
|
|
27
|
+
// Lowest value (64 bytes of zeroes)
|
|
28
|
+
putativeSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
29
|
+
putativeSignature.length > 88
|
|
30
|
+
) {
|
|
31
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
32
|
+
}
|
|
33
|
+
const bytes = base58Encoder.encode(putativeSignature);
|
|
34
|
+
const numBytes = bytes.byteLength;
|
|
35
|
+
if (numBytes !== 64) {
|
|
36
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
37
|
+
}
|
|
38
|
+
} catch (e) {
|
|
39
|
+
throw new Error(`\`${putativeSignature}\` is not a signature`, {
|
|
40
|
+
cause: e
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
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
|
+
}
|
|
20
61
|
async function signBytes(key, data) {
|
|
21
62
|
await assertions.assertSigningCapabilityIsAvailable();
|
|
22
63
|
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
23
64
|
return new Uint8Array(signedData);
|
|
24
65
|
}
|
|
25
|
-
|
|
66
|
+
function signature(putativeSignature) {
|
|
67
|
+
assertIsSignature(putativeSignature);
|
|
68
|
+
return putativeSignature;
|
|
69
|
+
}
|
|
70
|
+
async function verifySignature(key, signature2, data) {
|
|
26
71
|
await assertions.assertVerificationCapabilityIsAvailable();
|
|
27
|
-
return await crypto.subtle.verify("Ed25519", key,
|
|
72
|
+
return await crypto.subtle.verify("Ed25519", key, signature2, data);
|
|
28
73
|
}
|
|
29
74
|
|
|
75
|
+
exports.assertIsSignature = assertIsSignature;
|
|
30
76
|
exports.generateKeyPair = generateKeyPair;
|
|
77
|
+
exports.isSignature = isSignature;
|
|
31
78
|
exports.signBytes = signBytes;
|
|
79
|
+
exports.signature = signature;
|
|
32
80
|
exports.verifySignature = verifySignature;
|
|
33
81
|
//# sourceMappingURL=out.js.map
|
|
34
82
|
//# sourceMappingURL=index.node.cjs.map
|
package/dist/index.node.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
{"version":3,"sources":["../src/key-pair.ts","../src/signatures.ts"],"names":["signature"],"mappings":";AAAA,SAAS,sCAAsC;AAE/C,eAAsB,kBAA0C;AAC5D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BAAgB,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"]}
|
package/dist/index.node.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';
|
|
2
|
+
import { getBase58Encoder } from '@solana/codecs-strings';
|
|
2
3
|
|
|
3
4
|
// src/key-pair.ts
|
|
4
5
|
async function generateKeyPair() {
|
|
@@ -15,16 +16,60 @@ async function generateKeyPair() {
|
|
|
15
16
|
);
|
|
16
17
|
return keyPair;
|
|
17
18
|
}
|
|
19
|
+
var base58Encoder;
|
|
20
|
+
function assertIsSignature(putativeSignature) {
|
|
21
|
+
if (!base58Encoder)
|
|
22
|
+
base58Encoder = getBase58Encoder();
|
|
23
|
+
try {
|
|
24
|
+
if (
|
|
25
|
+
// Lowest value (64 bytes of zeroes)
|
|
26
|
+
putativeSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
27
|
+
putativeSignature.length > 88
|
|
28
|
+
) {
|
|
29
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
30
|
+
}
|
|
31
|
+
const bytes = base58Encoder.encode(putativeSignature);
|
|
32
|
+
const numBytes = bytes.byteLength;
|
|
33
|
+
if (numBytes !== 64) {
|
|
34
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
throw new Error(`\`${putativeSignature}\` is not a signature`, {
|
|
38
|
+
cause: e
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
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
|
+
}
|
|
18
59
|
async function signBytes(key, data) {
|
|
19
60
|
await assertSigningCapabilityIsAvailable();
|
|
20
61
|
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
21
62
|
return new Uint8Array(signedData);
|
|
22
63
|
}
|
|
23
|
-
|
|
64
|
+
function signature(putativeSignature) {
|
|
65
|
+
assertIsSignature(putativeSignature);
|
|
66
|
+
return putativeSignature;
|
|
67
|
+
}
|
|
68
|
+
async function verifySignature(key, signature2, data) {
|
|
24
69
|
await assertVerificationCapabilityIsAvailable();
|
|
25
|
-
return await crypto.subtle.verify("Ed25519", key,
|
|
70
|
+
return await crypto.subtle.verify("Ed25519", key, signature2, data);
|
|
26
71
|
}
|
|
27
72
|
|
|
28
|
-
export { generateKeyPair, signBytes, verifySignature };
|
|
73
|
+
export { assertIsSignature, generateKeyPair, isSignature, signBytes, signature, verifySignature };
|
|
29
74
|
//# sourceMappingURL=out.js.map
|
|
30
75
|
//# sourceMappingURL=index.node.js.map
|
package/dist/index.node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,15 +2,18 @@ this.globalThis = this.globalThis || {};
|
|
|
2
2
|
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
function
|
|
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(){if(u(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.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
7
|
Install and import \`@solana/webcrypto-ed25519-polyfill\` before generating keys in environments that do not support Ed25519.
|
|
8
8
|
|
|
9
|
-
For a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20`)}async function
|
|
9
|
+
For a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20`)}async function m(){if(u(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.sign!="function")throw new Error("No signing implementation could be found")}async function x(){if(u(),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 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
10
|
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
11
|
+
exports.assertIsSignature = C;
|
|
12
|
+
exports.generateKeyPair = D;
|
|
13
|
+
exports.isSignature = X;
|
|
14
|
+
exports.signBytes = R;
|
|
15
|
+
exports.signature = V;
|
|
16
|
+
exports.verifySignature = O;
|
|
14
17
|
|
|
15
18
|
return exports;
|
|
16
19
|
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type Signature = string & {
|
|
2
2
|
readonly __brand: unique symbol;
|
|
3
3
|
};
|
|
4
|
-
export
|
|
5
|
-
|
|
4
|
+
export type SignatureBytes = Uint8Array & {
|
|
5
|
+
readonly __brand: unique symbol;
|
|
6
|
+
};
|
|
7
|
+
export declare function assertIsSignature(putativeSignature: string): asserts putativeSignature is Signature;
|
|
8
|
+
export declare function isSignature(putativeSignature: string): putativeSignature is Signature;
|
|
9
|
+
export declare function signBytes(key: CryptoKey, data: Uint8Array): Promise<SignatureBytes>;
|
|
10
|
+
export declare function signature(putativeSignature: string): Signature;
|
|
11
|
+
export declare function verifySignature(key: CryptoKey, signature: SignatureBytes, data: Uint8Array): Promise<boolean>;
|
|
6
12
|
//# sourceMappingURL=signatures.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/keys",
|
|
3
|
-
"version": "2.0.0-experimental.
|
|
3
|
+
"version": "2.0.0-experimental.433f475",
|
|
4
4
|
"description": "Helpers for generating and transforming key material",
|
|
5
5
|
"exports": {
|
|
6
6
|
"browser": {
|
|
@@ -49,7 +49,9 @@
|
|
|
49
49
|
"node": ">=17.4"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@solana/assertions": "2.0.0-experimental.
|
|
52
|
+
"@solana/assertions": "2.0.0-experimental.433f475",
|
|
53
|
+
"@solana/codecs-core": "2.0.0-experimental.433f475",
|
|
54
|
+
"@solana/codecs-strings": "2.0.0-experimental.433f475"
|
|
53
55
|
},
|
|
54
56
|
"devDependencies": {
|
|
55
57
|
"@solana/eslint-config-solana": "^1.0.2",
|