@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.
- package/LICENSE +1 -1
- package/README.md +85 -15
- package/dist/index.browser.cjs +64 -26
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +59 -21
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +159 -198
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +59 -21
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +64 -26
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +59 -21
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +11 -3
- package/dist/types/index.d.ts +2 -1
- package/dist/types/key-pair.d.ts +2 -0
- package/dist/types/signatures.d.ts +12 -0
- package/package.json +25 -23
- package/dist/types/base58.d.ts +0 -6
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -18,35 +18,105 @@ This package contains utilities for validating, generating, and manipulating add
|
|
|
18
18
|
|
|
19
19
|
## Types
|
|
20
20
|
|
|
21
|
-
### `
|
|
21
|
+
### `Signature`
|
|
22
22
|
|
|
23
|
-
This type represents a
|
|
23
|
+
This type represents a 64-byte Ed25519 signature of some data with a private key, as a base58-encoded string.
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
### `SignatureBytes`
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
This type represents a 64-byte Ed25519 signature of some data with a private key.
|
|
28
|
+
|
|
29
|
+
Whenever you need to verify that a particular signature is, in fact, the one that would have been produced by signing some known bytes using the private key associated with some known public key, use the `verifySignature()` function in this package.
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
## Functions
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
### `assertIsSignature()`
|
|
32
34
|
|
|
33
|
-
From time to time you might acquire a string
|
|
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.
|
|
34
36
|
|
|
35
37
|
```ts
|
|
36
|
-
import {
|
|
38
|
+
import { assertIsSignature } from '@solana/keys';
|
|
37
39
|
|
|
38
|
-
// Imagine a function that
|
|
40
|
+
// Imagine a function that asserts whether a user-supplied signature is valid or not.
|
|
39
41
|
function handleSubmit() {
|
|
40
42
|
// We know only that what the user typed conforms to the `string` type.
|
|
41
|
-
const
|
|
43
|
+
const signature: string = signatureInput.value;
|
|
42
44
|
try {
|
|
43
45
|
// If this type assertion function doesn't throw, then
|
|
44
|
-
// Typescript will upcast `
|
|
45
|
-
|
|
46
|
-
// At this point, `
|
|
47
|
-
const
|
|
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();
|
|
48
52
|
} catch (e) {
|
|
49
|
-
// `
|
|
53
|
+
// `signature` turned out not to be a base58-encoded signature
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
56
|
```
|
|
57
|
+
|
|
58
|
+
### `generateKeyPair()`
|
|
59
|
+
|
|
60
|
+
Generates an Ed25519 public/private key pair for use with other methods in this package that accept `CryptoKey` objects.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { generateKeyPair } from '@solana/keys';
|
|
64
|
+
|
|
65
|
+
const { privateKey, publicKey } = await generateKeyPair();
|
|
66
|
+
```
|
|
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
|
+
|
|
87
|
+
### `signBytes()`
|
|
88
|
+
|
|
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`.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { signBytes } from '@solana/keys';
|
|
93
|
+
|
|
94
|
+
const data = new Uint8Array([1, 2, 3]);
|
|
95
|
+
const signature = await signBytes(privateKey, data);
|
|
96
|
+
```
|
|
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
|
+
|
|
111
|
+
### `verifySignature()`
|
|
112
|
+
|
|
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.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { verifySignature } from '@solana/keys';
|
|
117
|
+
|
|
118
|
+
const data = new Uint8Array([1, 2, 3]);
|
|
119
|
+
if (!(await verifySignature(publicKey, signature, data))) {
|
|
120
|
+
throw new Error('The data were *not* signed by the private key associated with `publicKey`');
|
|
121
|
+
}
|
|
122
|
+
```
|
package/dist/index.browser.cjs
CHANGED
|
@@ -1,44 +1,82 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var assertions = require('@solana/assertions');
|
|
4
|
+
var codecsStrings = require('@solana/codecs-strings');
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
31
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
18
32
|
}
|
|
19
|
-
const bytes =
|
|
33
|
+
const bytes = base58Encoder.encode(putativeSignature);
|
|
20
34
|
const numBytes = bytes.byteLength;
|
|
21
|
-
if (numBytes !==
|
|
22
|
-
throw new Error(`Expected input string to decode to a byte array of length
|
|
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(`\`${
|
|
39
|
+
throw new Error(`\`${putativeSignature}\` is not a signature`, {
|
|
26
40
|
cause: e
|
|
27
41
|
});
|
|
28
42
|
}
|
|
29
43
|
}
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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.
|
|
42
|
-
exports.
|
|
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.browser.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
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,37 +1,75 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';
|
|
2
|
+
import { getBase58Encoder } from '@solana/codecs-strings';
|
|
2
3
|
|
|
3
|
-
// src/
|
|
4
|
-
function
|
|
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
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
29
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
12
30
|
}
|
|
13
|
-
const bytes =
|
|
31
|
+
const bytes = base58Encoder.encode(putativeSignature);
|
|
14
32
|
const numBytes = bytes.byteLength;
|
|
15
|
-
if (numBytes !==
|
|
16
|
-
throw new Error(`Expected input string to decode to a byte array of length
|
|
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(`\`${
|
|
37
|
+
throw new Error(`\`${putativeSignature}\` is not a signature`, {
|
|
20
38
|
cause: e
|
|
21
39
|
});
|
|
22
40
|
}
|
|
23
41
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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 {
|
|
73
|
+
export { assertIsSignature, generateKeyPair, isSignature, signBytes, signature, verifySignature };
|
|
36
74
|
//# sourceMappingURL=out.js.map
|
|
37
75
|
//# sourceMappingURL=index.browser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
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"]}
|