@solana/keys 2.0.0-experimental.eefafdf → 2.0.0-experimental.f040ea3
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 +30 -21
- package/dist/index.browser.cjs +26 -36
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +24 -31
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +75 -206
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +24 -31
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +26 -36
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +24 -31
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +8 -3
- package/dist/types/index.d.ts +2 -1
- package/dist/types/key-pair.d.ts +2 -0
- package/dist/types/signatures.d.ts +6 -0
- package/package.json +22 -22
- package/dist/types/base58.d.ts +0 -6
package/README.md
CHANGED
|
@@ -18,35 +18,44 @@ This package contains utilities for validating, generating, and manipulating add
|
|
|
18
18
|
|
|
19
19
|
## Types
|
|
20
20
|
|
|
21
|
-
### `
|
|
21
|
+
### `Ed25519Signature`
|
|
22
22
|
|
|
23
|
-
This type represents a
|
|
23
|
+
This type represents a 64-byte Ed25519 signature of some data with a private key.
|
|
24
24
|
|
|
25
|
-
Whenever you need to
|
|
25
|
+
Whenever you need to verify that a particular signature is, in fact, the one that would have been produced by signing some known bytes using the private key associated with some known public key, use the `verifySignature()` function in this package.
|
|
26
26
|
|
|
27
27
|
## Functions
|
|
28
28
|
|
|
29
|
-
### `
|
|
29
|
+
### `generateKeyPair()`
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
Generates an Ed25519 public/private key pair for use with other methods in this package that accept `CryptoKey` objects.
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
```ts
|
|
34
|
+
import { generateKeyPair } from '@solana/keys';
|
|
35
|
+
|
|
36
|
+
const { privateKey, publicKey } = await generateKeyPair();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### `signBytes()`
|
|
40
|
+
|
|
41
|
+
Given a private `CryptoKey` and a `Uint8Array` of bytes, this method will return the 64-byte Ed25519 signature of that data as a `Uint8Array`.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { signBytes } from '@solana/keys';
|
|
45
|
+
|
|
46
|
+
const data = new Uint8Array([1, 2, 3]);
|
|
47
|
+
const signature = await signBytes(privateKey, data);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### `verifySignature()`
|
|
51
|
+
|
|
52
|
+
Given a public `CryptoKey`, an `Ed25519Signature`, and a `Uint8Array` of bytes, this method will return `true` if the signature was produced by signing the bytes using the private key associated with the public key, and `false` otherwise.
|
|
34
53
|
|
|
35
54
|
```ts
|
|
36
|
-
import {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const address: string = accountAddressInput.value;
|
|
42
|
-
try {
|
|
43
|
-
// If this type assertion function doesn't throw, then
|
|
44
|
-
// Typescript will upcast `address` to `Base58EncodedAddress`.
|
|
45
|
-
assertIsBase58EncodedAddress(address);
|
|
46
|
-
// At this point, `address` is a `Base58EncodedAddress` that can be used with the RPC.
|
|
47
|
-
const balanceInLamports = await rpc.getBalance(address).send();
|
|
48
|
-
} catch (e) {
|
|
49
|
-
// `address` turned out not to be a base58-encoded address
|
|
50
|
-
}
|
|
55
|
+
import { verifySignature } from '@solana/keys';
|
|
56
|
+
|
|
57
|
+
const data = new Uint8Array([1, 2, 3]);
|
|
58
|
+
if (!(await verifySignature(publicKey, signature, data))) {
|
|
59
|
+
throw new Error('The data were *not* signed by the private key associated with `publicKey`');
|
|
51
60
|
}
|
|
52
61
|
```
|
package/dist/index.browser.cjs
CHANGED
|
@@ -1,44 +1,34 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var assertions = require('@solana/assertions');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} catch (e) {
|
|
25
|
-
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
26
|
-
cause: e
|
|
27
|
-
});
|
|
28
|
-
}
|
|
5
|
+
// src/key-pair.ts
|
|
6
|
+
async function generateKeyPair() {
|
|
7
|
+
await assertions.assertKeyGenerationIsAvailable();
|
|
8
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
9
|
+
/* algorithm */
|
|
10
|
+
"Ed25519",
|
|
11
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
12
|
+
/* extractable */
|
|
13
|
+
false,
|
|
14
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
15
|
+
/* allowed uses */
|
|
16
|
+
["sign", "verify"]
|
|
17
|
+
);
|
|
18
|
+
return keyPair;
|
|
19
|
+
}
|
|
20
|
+
async function signBytes(key, data) {
|
|
21
|
+
await assertions.assertSigningCapabilityIsAvailable();
|
|
22
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
23
|
+
return new Uint8Array(signedData);
|
|
29
24
|
}
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
ignorePunctuation: false,
|
|
34
|
-
localeMatcher: "best fit",
|
|
35
|
-
numeric: false,
|
|
36
|
-
sensitivity: "variant",
|
|
37
|
-
usage: "sort"
|
|
38
|
-
}).compare;
|
|
25
|
+
async function verifySignature(key, signature, data) {
|
|
26
|
+
await assertions.assertVerificationCapabilityIsAvailable();
|
|
27
|
+
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
39
28
|
}
|
|
40
29
|
|
|
41
|
-
exports.
|
|
42
|
-
exports.
|
|
30
|
+
exports.generateKeyPair = generateKeyPair;
|
|
31
|
+
exports.signBytes = signBytes;
|
|
32
|
+
exports.verifySignature = verifySignature;
|
|
43
33
|
//# sourceMappingURL=out.js.map
|
|
44
34
|
//# sourceMappingURL=index.browser.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/key-pair.ts","../src/signatures.ts"],"names":[],"mappings":";AAAA,SAAS,sCAAsC;AAE/C,eAAsB,kBAA0C;AAC5D,QAAM,+BAA+B;AACrC,QAAM,UAAU,MAAM,OAAO,OAAO;AAAA;AAAA,IAChB;AAAA;AAAA;AAAA,IACE;AAAA;AAAA;AAAA,IACC,CAAC,QAAQ,QAAQ;AAAA,EACxC;AACA,SAAO;AACX;;;ACVA,SAAS,oCAAoC,+CAA+C;AAI5F,eAAsB,UAAU,KAAgB,MAA6C;AACzF,QAAM,mCAAmC;AACzC,QAAM,aAAa,MAAM,OAAO,OAAO,KAAK,WAAW,KAAK,IAAI;AAChE,SAAO,IAAI,WAAW,UAAU;AACpC;AAEA,eAAsB,gBAAgB,KAAgB,WAA6B,MAAoC;AACnH,QAAM,wCAAwC;AAC9C,SAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK,WAAW,IAAI;AACrE","sourcesContent":["import { assertKeyGenerationIsAvailable } from '@solana/assertions';\n\nexport async function generateKeyPair(): Promise<CryptoKeyPair> {\n await assertKeyGenerationIsAvailable();\n const keyPair = await crypto.subtle.generateKey(\n /* algorithm */ 'Ed25519', // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20\n /* extractable */ false, // Prevents the bytes of the private key from being visible to JS.\n /* allowed uses */ ['sign', 'verify']\n );\n return keyPair as CryptoKeyPair;\n}\n","import { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\n\nexport type Ed25519Signature = Uint8Array & { readonly __brand: unique symbol };\n\nexport async function signBytes(key: CryptoKey, data: Uint8Array): Promise<Ed25519Signature> {\n await assertSigningCapabilityIsAvailable();\n const signedData = await crypto.subtle.sign('Ed25519', key, data);\n return new Uint8Array(signedData) as Ed25519Signature;\n}\n\nexport async function verifySignature(key: CryptoKey, signature: Ed25519Signature, data: Uint8Array): Promise<boolean> {\n await assertVerificationCapabilityIsAvailable();\n return await crypto.subtle.verify('Ed25519', key, signature, data);\n}\n"]}
|
package/dist/index.browser.js
CHANGED
|
@@ -1,37 +1,30 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';
|
|
2
2
|
|
|
3
|
-
// src/
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
} catch (e) {
|
|
19
|
-
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
20
|
-
cause: e
|
|
21
|
-
});
|
|
22
|
-
}
|
|
3
|
+
// src/key-pair.ts
|
|
4
|
+
async function generateKeyPair() {
|
|
5
|
+
await assertKeyGenerationIsAvailable();
|
|
6
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
7
|
+
/* algorithm */
|
|
8
|
+
"Ed25519",
|
|
9
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
10
|
+
/* extractable */
|
|
11
|
+
false,
|
|
12
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
13
|
+
/* allowed uses */
|
|
14
|
+
["sign", "verify"]
|
|
15
|
+
);
|
|
16
|
+
return keyPair;
|
|
23
17
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}).compare;
|
|
18
|
+
async function signBytes(key, data) {
|
|
19
|
+
await assertSigningCapabilityIsAvailable();
|
|
20
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
21
|
+
return new Uint8Array(signedData);
|
|
22
|
+
}
|
|
23
|
+
async function verifySignature(key, signature, data) {
|
|
24
|
+
await assertVerificationCapabilityIsAvailable();
|
|
25
|
+
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
33
26
|
}
|
|
34
27
|
|
|
35
|
-
export {
|
|
28
|
+
export { generateKeyPair, signBytes, verifySignature };
|
|
36
29
|
//# sourceMappingURL=out.js.map
|
|
37
30
|
//# sourceMappingURL=index.browser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/key-pair.ts","../src/signatures.ts"],"names":[],"mappings":";AAAA,SAAS,sCAAsC;AAE/C,eAAsB,kBAA0C;AAC5D,QAAM,+BAA+B;AACrC,QAAM,UAAU,MAAM,OAAO,OAAO;AAAA;AAAA,IAChB;AAAA;AAAA;AAAA,IACE;AAAA;AAAA;AAAA,IACC,CAAC,QAAQ,QAAQ;AAAA,EACxC;AACA,SAAO;AACX;;;ACVA,SAAS,oCAAoC,+CAA+C;AAI5F,eAAsB,UAAU,KAAgB,MAA6C;AACzF,QAAM,mCAAmC;AACzC,QAAM,aAAa,MAAM,OAAO,OAAO,KAAK,WAAW,KAAK,IAAI;AAChE,SAAO,IAAI,WAAW,UAAU;AACpC;AAEA,eAAsB,gBAAgB,KAAgB,WAA6B,MAAoC;AACnH,QAAM,wCAAwC;AAC9C,SAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK,WAAW,IAAI;AACrE","sourcesContent":["import { assertKeyGenerationIsAvailable } from '@solana/assertions';\n\nexport async function generateKeyPair(): Promise<CryptoKeyPair> {\n await assertKeyGenerationIsAvailable();\n const keyPair = await crypto.subtle.generateKey(\n /* algorithm */ 'Ed25519', // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20\n /* extractable */ false, // Prevents the bytes of the private key from being visible to JS.\n /* allowed uses */ ['sign', 'verify']\n );\n return keyPair as CryptoKeyPair;\n}\n","import { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\n\nexport type Ed25519Signature = Uint8Array & { readonly __brand: unique symbol };\n\nexport async function signBytes(key: CryptoKey, data: Uint8Array): Promise<Ed25519Signature> {\n await assertSigningCapabilityIsAvailable();\n const signedData = await crypto.subtle.sign('Ed25519', key, data);\n return new Uint8Array(signedData) as Ed25519Signature;\n}\n\nexport async function verifySignature(key: CryptoKey, signature: Ed25519Signature, data: Uint8Array): Promise<boolean> {\n await assertVerificationCapabilityIsAvailable();\n return await crypto.subtle.verify('Ed25519', key, signature, data);\n}\n"]}
|
|
@@ -2,221 +2,90 @@ this.globalThis = this.globalThis || {};
|
|
|
2
2
|
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var __esm = (fn, res) => function __init() {
|
|
12
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
13
|
-
};
|
|
14
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
15
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
|
-
};
|
|
17
|
-
var __copyProps = (to, from, except, desc) => {
|
|
18
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
-
for (let key of __getOwnPropNames(from))
|
|
20
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
5
|
+
// ../assertions/dist/index.browser.js
|
|
6
|
+
function assertIsSecureContext() {
|
|
7
|
+
if (!globalThis.isSecureContext) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
|
|
10
|
+
);
|
|
22
11
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
12
|
+
}
|
|
13
|
+
var cachedEd25519Decision;
|
|
14
|
+
async function isEd25519CurveSupported(subtle) {
|
|
15
|
+
if (cachedEd25519Decision === void 0) {
|
|
16
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
17
|
+
subtle.generateKey(
|
|
18
|
+
"Ed25519",
|
|
19
|
+
/* extractable */
|
|
20
|
+
false,
|
|
21
|
+
["sign", "verify"]
|
|
22
|
+
).catch(() => {
|
|
23
|
+
resolve(cachedEd25519Decision = false);
|
|
24
|
+
}).then(() => {
|
|
25
|
+
resolve(cachedEd25519Decision = true);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
37
28
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"../../node_modules/.pnpm/base-x@4.0.0/node_modules/base-x/src/index.js"(exports, module) {
|
|
43
|
-
init_env_shim();
|
|
44
|
-
function base(ALPHABET) {
|
|
45
|
-
if (ALPHABET.length >= 255) {
|
|
46
|
-
throw new TypeError("Alphabet too long");
|
|
47
|
-
}
|
|
48
|
-
var BASE_MAP = new Uint8Array(256);
|
|
49
|
-
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
50
|
-
BASE_MAP[j] = 255;
|
|
51
|
-
}
|
|
52
|
-
for (var i = 0; i < ALPHABET.length; i++) {
|
|
53
|
-
var x = ALPHABET.charAt(i);
|
|
54
|
-
var xc = x.charCodeAt(0);
|
|
55
|
-
if (BASE_MAP[xc] !== 255) {
|
|
56
|
-
throw new TypeError(x + " is ambiguous");
|
|
57
|
-
}
|
|
58
|
-
BASE_MAP[xc] = i;
|
|
59
|
-
}
|
|
60
|
-
var BASE = ALPHABET.length;
|
|
61
|
-
var LEADER = ALPHABET.charAt(0);
|
|
62
|
-
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
63
|
-
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
64
|
-
function encode(source) {
|
|
65
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
66
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
67
|
-
} else if (Array.isArray(source)) {
|
|
68
|
-
source = Uint8Array.from(source);
|
|
69
|
-
}
|
|
70
|
-
if (!(source instanceof Uint8Array)) {
|
|
71
|
-
throw new TypeError("Expected Uint8Array");
|
|
72
|
-
}
|
|
73
|
-
if (source.length === 0) {
|
|
74
|
-
return "";
|
|
75
|
-
}
|
|
76
|
-
var zeroes = 0;
|
|
77
|
-
var length = 0;
|
|
78
|
-
var pbegin = 0;
|
|
79
|
-
var pend = source.length;
|
|
80
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
81
|
-
pbegin++;
|
|
82
|
-
zeroes++;
|
|
83
|
-
}
|
|
84
|
-
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
85
|
-
var b58 = new Uint8Array(size);
|
|
86
|
-
while (pbegin !== pend) {
|
|
87
|
-
var carry = source[pbegin];
|
|
88
|
-
var i2 = 0;
|
|
89
|
-
for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) {
|
|
90
|
-
carry += 256 * b58[it1] >>> 0;
|
|
91
|
-
b58[it1] = carry % BASE >>> 0;
|
|
92
|
-
carry = carry / BASE >>> 0;
|
|
93
|
-
}
|
|
94
|
-
if (carry !== 0) {
|
|
95
|
-
throw new Error("Non-zero carry");
|
|
96
|
-
}
|
|
97
|
-
length = i2;
|
|
98
|
-
pbegin++;
|
|
99
|
-
}
|
|
100
|
-
var it2 = size - length;
|
|
101
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
102
|
-
it2++;
|
|
103
|
-
}
|
|
104
|
-
var str = LEADER.repeat(zeroes);
|
|
105
|
-
for (; it2 < size; ++it2) {
|
|
106
|
-
str += ALPHABET.charAt(b58[it2]);
|
|
107
|
-
}
|
|
108
|
-
return str;
|
|
109
|
-
}
|
|
110
|
-
function decodeUnsafe(source) {
|
|
111
|
-
if (typeof source !== "string") {
|
|
112
|
-
throw new TypeError("Expected String");
|
|
113
|
-
}
|
|
114
|
-
if (source.length === 0) {
|
|
115
|
-
return new Uint8Array();
|
|
116
|
-
}
|
|
117
|
-
var psz = 0;
|
|
118
|
-
var zeroes = 0;
|
|
119
|
-
var length = 0;
|
|
120
|
-
while (source[psz] === LEADER) {
|
|
121
|
-
zeroes++;
|
|
122
|
-
psz++;
|
|
123
|
-
}
|
|
124
|
-
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
125
|
-
var b256 = new Uint8Array(size);
|
|
126
|
-
while (source[psz]) {
|
|
127
|
-
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
128
|
-
if (carry === 255) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
var i2 = 0;
|
|
132
|
-
for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) {
|
|
133
|
-
carry += BASE * b256[it3] >>> 0;
|
|
134
|
-
b256[it3] = carry % 256 >>> 0;
|
|
135
|
-
carry = carry / 256 >>> 0;
|
|
136
|
-
}
|
|
137
|
-
if (carry !== 0) {
|
|
138
|
-
throw new Error("Non-zero carry");
|
|
139
|
-
}
|
|
140
|
-
length = i2;
|
|
141
|
-
psz++;
|
|
142
|
-
}
|
|
143
|
-
var it4 = size - length;
|
|
144
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
145
|
-
it4++;
|
|
146
|
-
}
|
|
147
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
148
|
-
var j2 = zeroes;
|
|
149
|
-
while (it4 !== size) {
|
|
150
|
-
vch[j2++] = b256[it4++];
|
|
151
|
-
}
|
|
152
|
-
return vch;
|
|
153
|
-
}
|
|
154
|
-
function decode(string) {
|
|
155
|
-
var buffer = decodeUnsafe(string);
|
|
156
|
-
if (buffer) {
|
|
157
|
-
return buffer;
|
|
158
|
-
}
|
|
159
|
-
throw new Error("Non-base" + BASE + " character");
|
|
160
|
-
}
|
|
161
|
-
return {
|
|
162
|
-
encode,
|
|
163
|
-
decodeUnsafe,
|
|
164
|
-
decode
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
module.exports = base;
|
|
29
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
30
|
+
return cachedEd25519Decision;
|
|
31
|
+
} else {
|
|
32
|
+
return await cachedEd25519Decision;
|
|
168
33
|
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
init_env_shim();
|
|
175
|
-
var basex = require_src();
|
|
176
|
-
var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
177
|
-
module.exports = basex(ALPHABET);
|
|
34
|
+
}
|
|
35
|
+
async function assertKeyGenerationIsAvailable() {
|
|
36
|
+
assertIsSecureContext();
|
|
37
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
38
|
+
throw new Error("No key generation implementation could be found");
|
|
178
39
|
}
|
|
179
|
-
|
|
40
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function assertSigningCapabilityIsAvailable() {
|
|
47
|
+
assertIsSecureContext();
|
|
48
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
49
|
+
throw new Error("No signing implementation could be found");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function assertVerificationCapabilityIsAvailable() {
|
|
53
|
+
assertIsSecureContext();
|
|
54
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
|
|
55
|
+
throw new Error("No signature verification implementation could be found");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
180
58
|
|
|
181
|
-
// src/
|
|
182
|
-
|
|
59
|
+
// src/key-pair.ts
|
|
60
|
+
async function generateKeyPair() {
|
|
61
|
+
await assertKeyGenerationIsAvailable();
|
|
62
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
63
|
+
/* algorithm */
|
|
64
|
+
"Ed25519",
|
|
65
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
66
|
+
/* extractable */
|
|
67
|
+
false,
|
|
68
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
69
|
+
/* allowed uses */
|
|
70
|
+
["sign", "verify"]
|
|
71
|
+
);
|
|
72
|
+
return keyPair;
|
|
73
|
+
}
|
|
183
74
|
|
|
184
|
-
// src/
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (
|
|
190
|
-
// Lowest address (32 bytes of zeroes)
|
|
191
|
-
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
192
|
-
putativeBase58EncodedAddress.length > 44
|
|
193
|
-
) {
|
|
194
|
-
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
195
|
-
}
|
|
196
|
-
const bytes = import_bs58.default.decode(putativeBase58EncodedAddress);
|
|
197
|
-
const numBytes = bytes.byteLength;
|
|
198
|
-
if (numBytes !== 32) {
|
|
199
|
-
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
200
|
-
}
|
|
201
|
-
} catch (e) {
|
|
202
|
-
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
203
|
-
cause: e
|
|
204
|
-
});
|
|
205
|
-
}
|
|
75
|
+
// src/signatures.ts
|
|
76
|
+
async function signBytes(key, data) {
|
|
77
|
+
await assertSigningCapabilityIsAvailable();
|
|
78
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
79
|
+
return new Uint8Array(signedData);
|
|
206
80
|
}
|
|
207
|
-
function
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
ignorePunctuation: false,
|
|
211
|
-
localeMatcher: "best fit",
|
|
212
|
-
numeric: false,
|
|
213
|
-
sensitivity: "variant",
|
|
214
|
-
usage: "sort"
|
|
215
|
-
}).compare;
|
|
81
|
+
async function verifySignature(key, signature, data) {
|
|
82
|
+
await assertVerificationCapabilityIsAvailable();
|
|
83
|
+
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
216
84
|
}
|
|
217
85
|
|
|
218
|
-
exports.
|
|
219
|
-
exports.
|
|
86
|
+
exports.generateKeyPair = generateKeyPair;
|
|
87
|
+
exports.signBytes = signBytes;
|
|
88
|
+
exports.verifySignature = verifySignature;
|
|
220
89
|
|
|
221
90
|
return exports;
|
|
222
91
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../
|
|
1
|
+
{"version":3,"sources":["../../assertions/src/subtle-crypto.ts","../src/key-pair.ts","../src/signatures.ts"],"names":[],"mappings":";AAAA,SAAS,wBAAwB;AAC7B,MAAmB,CAAC,WAAW,iBAAiB;AAE5C,UAAM,IAAI;MACN;IAEJ;EACJ;AACJ;AAEA,IAAI;AACJ,eAAe,wBAAwB,QAAwC;AAC3E,MAAI,0BAA0B,QAAW;AACrC,4BAAwB,IAAI,QAAQ,CAAA,YAAW;AAC3C,aACK;QAAY;;QAA6B;QAAO,CAAC,QAAQ,QAAQ;MAAC,EAClE,MAAM,MAAM;AACT,gBAAS,wBAAwB,KAAM;MAC3C,CAAC,EACA,KAAK,MAAM;AACR,gBAAS,wBAAwB,IAAK;MAC1C,CAAC;IACT,CAAC;EACL;AACA,MAAI,OAAO,0BAA0B,WAAW;AAC5C,WAAO;EACX,OAAO;AACH,WAAO,MAAM;EACjB;AACJ;AAUA,eAAsB,iCAAiC;AACnD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,gBAAgB,YAAY;AAEzG,UAAM,IAAI,MAAM,iDAAiD;EACrE;AACA,MAAI,CAAE,MAAM,wBAAwB,WAAW,OAAO,MAAM,GAAI;AAE5D,UAAM,IAAI;MACN;IAKJ;EACJ;AACJ;AAUA,eAAsB,qCAAqC;AACvD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,SAAS,YAAY;AAElG,UAAM,IAAI,MAAM,0CAA0C;EAC9D;AACJ;AAEA,eAAsB,0CAA0C;AAC5D,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AAEpG,UAAM,IAAI,MAAM,yDAAyD;EAC7E;AACJ;;;AC7EA,eAAsB,kBAA0C;AAC5D,QAAM,+BAA+B;AACrC,QAAM,UAAU,MAAM,OAAO,OAAO;AAAA;AAAA,IAChB;AAAA;AAAA;AAAA,IACE;AAAA;AAAA;AAAA,IACC,CAAC,QAAQ,QAAQ;AAAA,EACxC;AACA,SAAO;AACX;;;ACNA,eAAsB,UAAU,KAAgB,MAA6C;AACzF,QAAM,mCAAmC;AACzC,QAAM,aAAa,MAAM,OAAO,OAAO,KAAK,WAAW,KAAK,IAAI;AAChE,SAAO,IAAI,WAAW,UAAU;AACpC;AAEA,eAAsB,gBAAgB,KAAgB,WAA6B,MAAoC;AACnH,QAAM,wCAAwC;AAC9C,SAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK,WAAW,IAAI;AACrE","sourcesContent":["function assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n // TODO: Coded error.\n throw new Error(\n 'Cryptographic operations are only allowed in secure browser contexts. Read more ' +\n 'here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts'\n );\n }\n}\n\nlet cachedEd25519Decision: PromiseLike<boolean> | boolean | undefined;\nasync function isEd25519CurveSupported(subtle: SubtleCrypto): Promise<boolean> {\n if (cachedEd25519Decision === undefined) {\n cachedEd25519Decision = new Promise(resolve => {\n subtle\n .generateKey('Ed25519', /* extractable */ false, ['sign', 'verify'])\n .catch(() => {\n resolve((cachedEd25519Decision = false));\n })\n .then(() => {\n resolve((cachedEd25519Decision = true));\n });\n });\n }\n if (typeof cachedEd25519Decision === 'boolean') {\n return cachedEd25519Decision;\n } else {\n return await cachedEd25519Decision;\n }\n}\n\nexport async function assertDigestCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.digest !== 'function') {\n // TODO: Coded error.\n throw new Error('No digest implementation could be found');\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key generation implementation could be found');\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n // TODO: Coded error.\n throw new Error(\n 'This runtime does not support the generation of Ed25519 key pairs.\\n\\nInstall and ' +\n 'import `@solana/webcrypto-ed25519-polyfill` before generating keys in ' +\n 'environments that do not support Ed25519.\\n\\nFor a list of runtimes that ' +\n 'currently support Ed25519 operations, visit ' +\n 'https://github.com/WICG/webcrypto-secure-curves/issues/20'\n );\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key export implementation could be found');\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n // TODO: Coded error.\n throw new Error('No signing implementation could be found');\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n // TODO: Coded error.\n throw new Error('No signature verification implementation could be found');\n }\n}\n","import { assertKeyGenerationIsAvailable } from '@solana/assertions';\n\nexport async function generateKeyPair(): Promise<CryptoKeyPair> {\n await assertKeyGenerationIsAvailable();\n const keyPair = await crypto.subtle.generateKey(\n /* algorithm */ 'Ed25519', // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20\n /* extractable */ false, // Prevents the bytes of the private key from being visible to JS.\n /* allowed uses */ ['sign', 'verify']\n );\n return keyPair as CryptoKeyPair;\n}\n","import { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\n\nexport type Ed25519Signature = Uint8Array & { readonly __brand: unique symbol };\n\nexport async function signBytes(key: CryptoKey, data: Uint8Array): Promise<Ed25519Signature> {\n await assertSigningCapabilityIsAvailable();\n const signedData = await crypto.subtle.sign('Ed25519', key, data);\n return new Uint8Array(signedData) as Ed25519Signature;\n}\n\nexport async function verifySignature(key: CryptoKey, signature: Ed25519Signature, data: Uint8Array): Promise<boolean> {\n await assertVerificationCapabilityIsAvailable();\n return await crypto.subtle.verify('Ed25519', key, signature, data);\n}\n"]}
|
package/dist/index.native.js
CHANGED
|
@@ -1,37 +1,30 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';
|
|
2
2
|
|
|
3
|
-
// src/
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
} catch (e) {
|
|
19
|
-
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
20
|
-
cause: e
|
|
21
|
-
});
|
|
22
|
-
}
|
|
3
|
+
// src/key-pair.ts
|
|
4
|
+
async function generateKeyPair() {
|
|
5
|
+
await assertKeyGenerationIsAvailable();
|
|
6
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
7
|
+
/* algorithm */
|
|
8
|
+
"Ed25519",
|
|
9
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
10
|
+
/* extractable */
|
|
11
|
+
false,
|
|
12
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
13
|
+
/* allowed uses */
|
|
14
|
+
["sign", "verify"]
|
|
15
|
+
);
|
|
16
|
+
return keyPair;
|
|
23
17
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}).compare;
|
|
18
|
+
async function signBytes(key, data) {
|
|
19
|
+
await assertSigningCapabilityIsAvailable();
|
|
20
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
21
|
+
return new Uint8Array(signedData);
|
|
22
|
+
}
|
|
23
|
+
async function verifySignature(key, signature, data) {
|
|
24
|
+
await assertVerificationCapabilityIsAvailable();
|
|
25
|
+
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
33
26
|
}
|
|
34
27
|
|
|
35
|
-
export {
|
|
28
|
+
export { generateKeyPair, signBytes, verifySignature };
|
|
36
29
|
//# sourceMappingURL=out.js.map
|
|
37
30
|
//# sourceMappingURL=index.native.js.map
|
package/dist/index.native.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/key-pair.ts","../src/signatures.ts"],"names":[],"mappings":";AAAA,SAAS,sCAAsC;AAE/C,eAAsB,kBAA0C;AAC5D,QAAM,+BAA+B;AACrC,QAAM,UAAU,MAAM,OAAO,OAAO;AAAA;AAAA,IAChB;AAAA;AAAA;AAAA,IACE;AAAA;AAAA;AAAA,IACC,CAAC,QAAQ,QAAQ;AAAA,EACxC;AACA,SAAO;AACX;;;ACVA,SAAS,oCAAoC,+CAA+C;AAI5F,eAAsB,UAAU,KAAgB,MAA6C;AACzF,QAAM,mCAAmC;AACzC,QAAM,aAAa,MAAM,OAAO,OAAO,KAAK,WAAW,KAAK,IAAI;AAChE,SAAO,IAAI,WAAW,UAAU;AACpC;AAEA,eAAsB,gBAAgB,KAAgB,WAA6B,MAAoC;AACnH,QAAM,wCAAwC;AAC9C,SAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK,WAAW,IAAI;AACrE","sourcesContent":["import { assertKeyGenerationIsAvailable } from '@solana/assertions';\n\nexport async function generateKeyPair(): Promise<CryptoKeyPair> {\n await assertKeyGenerationIsAvailable();\n const keyPair = await crypto.subtle.generateKey(\n /* algorithm */ 'Ed25519', // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20\n /* extractable */ false, // Prevents the bytes of the private key from being visible to JS.\n /* allowed uses */ ['sign', 'verify']\n );\n return keyPair as CryptoKeyPair;\n}\n","import { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\n\nexport type Ed25519Signature = Uint8Array & { readonly __brand: unique symbol };\n\nexport async function signBytes(key: CryptoKey, data: Uint8Array): Promise<Ed25519Signature> {\n await assertSigningCapabilityIsAvailable();\n const signedData = await crypto.subtle.sign('Ed25519', key, data);\n return new Uint8Array(signedData) as Ed25519Signature;\n}\n\nexport async function verifySignature(key: CryptoKey, signature: Ed25519Signature, data: Uint8Array): Promise<boolean> {\n await assertVerificationCapabilityIsAvailable();\n return await crypto.subtle.verify('Ed25519', key, signature, data);\n}\n"]}
|
package/dist/index.node.cjs
CHANGED
|
@@ -1,44 +1,34 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var assertions = require('@solana/assertions');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} catch (e) {
|
|
25
|
-
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
26
|
-
cause: e
|
|
27
|
-
});
|
|
28
|
-
}
|
|
5
|
+
// src/key-pair.ts
|
|
6
|
+
async function generateKeyPair() {
|
|
7
|
+
await assertions.assertKeyGenerationIsAvailable();
|
|
8
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
9
|
+
/* algorithm */
|
|
10
|
+
"Ed25519",
|
|
11
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
12
|
+
/* extractable */
|
|
13
|
+
false,
|
|
14
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
15
|
+
/* allowed uses */
|
|
16
|
+
["sign", "verify"]
|
|
17
|
+
);
|
|
18
|
+
return keyPair;
|
|
19
|
+
}
|
|
20
|
+
async function signBytes(key, data) {
|
|
21
|
+
await assertions.assertSigningCapabilityIsAvailable();
|
|
22
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
23
|
+
return new Uint8Array(signedData);
|
|
29
24
|
}
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
ignorePunctuation: false,
|
|
34
|
-
localeMatcher: "best fit",
|
|
35
|
-
numeric: false,
|
|
36
|
-
sensitivity: "variant",
|
|
37
|
-
usage: "sort"
|
|
38
|
-
}).compare;
|
|
25
|
+
async function verifySignature(key, signature, data) {
|
|
26
|
+
await assertions.assertVerificationCapabilityIsAvailable();
|
|
27
|
+
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
39
28
|
}
|
|
40
29
|
|
|
41
|
-
exports.
|
|
42
|
-
exports.
|
|
30
|
+
exports.generateKeyPair = generateKeyPair;
|
|
31
|
+
exports.signBytes = signBytes;
|
|
32
|
+
exports.verifySignature = verifySignature;
|
|
43
33
|
//# sourceMappingURL=out.js.map
|
|
44
34
|
//# sourceMappingURL=index.node.cjs.map
|
package/dist/index.node.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/key-pair.ts","../src/signatures.ts"],"names":[],"mappings":";AAAA,SAAS,sCAAsC;AAE/C,eAAsB,kBAA0C;AAC5D,QAAM,+BAA+B;AACrC,QAAM,UAAU,MAAM,OAAO,OAAO;AAAA;AAAA,IAChB;AAAA;AAAA;AAAA,IACE;AAAA;AAAA;AAAA,IACC,CAAC,QAAQ,QAAQ;AAAA,EACxC;AACA,SAAO;AACX;;;ACVA,SAAS,oCAAoC,+CAA+C;AAI5F,eAAsB,UAAU,KAAgB,MAA6C;AACzF,QAAM,mCAAmC;AACzC,QAAM,aAAa,MAAM,OAAO,OAAO,KAAK,WAAW,KAAK,IAAI;AAChE,SAAO,IAAI,WAAW,UAAU;AACpC;AAEA,eAAsB,gBAAgB,KAAgB,WAA6B,MAAoC;AACnH,QAAM,wCAAwC;AAC9C,SAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK,WAAW,IAAI;AACrE","sourcesContent":["import { assertKeyGenerationIsAvailable } from '@solana/assertions';\n\nexport async function generateKeyPair(): Promise<CryptoKeyPair> {\n await assertKeyGenerationIsAvailable();\n const keyPair = await crypto.subtle.generateKey(\n /* algorithm */ 'Ed25519', // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20\n /* extractable */ false, // Prevents the bytes of the private key from being visible to JS.\n /* allowed uses */ ['sign', 'verify']\n );\n return keyPair as CryptoKeyPair;\n}\n","import { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\n\nexport type Ed25519Signature = Uint8Array & { readonly __brand: unique symbol };\n\nexport async function signBytes(key: CryptoKey, data: Uint8Array): Promise<Ed25519Signature> {\n await assertSigningCapabilityIsAvailable();\n const signedData = await crypto.subtle.sign('Ed25519', key, data);\n return new Uint8Array(signedData) as Ed25519Signature;\n}\n\nexport async function verifySignature(key: CryptoKey, signature: Ed25519Signature, data: Uint8Array): Promise<boolean> {\n await assertVerificationCapabilityIsAvailable();\n return await crypto.subtle.verify('Ed25519', key, signature, data);\n}\n"]}
|
package/dist/index.node.js
CHANGED
|
@@ -1,37 +1,30 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';
|
|
2
2
|
|
|
3
|
-
// src/
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
} catch (e) {
|
|
19
|
-
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
20
|
-
cause: e
|
|
21
|
-
});
|
|
22
|
-
}
|
|
3
|
+
// src/key-pair.ts
|
|
4
|
+
async function generateKeyPair() {
|
|
5
|
+
await assertKeyGenerationIsAvailable();
|
|
6
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
7
|
+
/* algorithm */
|
|
8
|
+
"Ed25519",
|
|
9
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
10
|
+
/* extractable */
|
|
11
|
+
false,
|
|
12
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
13
|
+
/* allowed uses */
|
|
14
|
+
["sign", "verify"]
|
|
15
|
+
);
|
|
16
|
+
return keyPair;
|
|
23
17
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}).compare;
|
|
18
|
+
async function signBytes(key, data) {
|
|
19
|
+
await assertSigningCapabilityIsAvailable();
|
|
20
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
21
|
+
return new Uint8Array(signedData);
|
|
22
|
+
}
|
|
23
|
+
async function verifySignature(key, signature, data) {
|
|
24
|
+
await assertVerificationCapabilityIsAvailable();
|
|
25
|
+
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
33
26
|
}
|
|
34
27
|
|
|
35
|
-
export {
|
|
28
|
+
export { generateKeyPair, signBytes, verifySignature };
|
|
36
29
|
//# sourceMappingURL=out.js.map
|
|
37
30
|
//# sourceMappingURL=index.node.js.map
|
package/dist/index.node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/key-pair.ts","../src/signatures.ts"],"names":[],"mappings":";AAAA,SAAS,sCAAsC;AAE/C,eAAsB,kBAA0C;AAC5D,QAAM,+BAA+B;AACrC,QAAM,UAAU,MAAM,OAAO,OAAO;AAAA;AAAA,IAChB;AAAA;AAAA;AAAA,IACE;AAAA;AAAA;AAAA,IACC,CAAC,QAAQ,QAAQ;AAAA,EACxC;AACA,SAAO;AACX;;;ACVA,SAAS,oCAAoC,+CAA+C;AAI5F,eAAsB,UAAU,KAAgB,MAA6C;AACzF,QAAM,mCAAmC;AACzC,QAAM,aAAa,MAAM,OAAO,OAAO,KAAK,WAAW,KAAK,IAAI;AAChE,SAAO,IAAI,WAAW,UAAU;AACpC;AAEA,eAAsB,gBAAgB,KAAgB,WAA6B,MAAoC;AACnH,QAAM,wCAAwC;AAC9C,SAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK,WAAW,IAAI;AACrE","sourcesContent":["import { assertKeyGenerationIsAvailable } from '@solana/assertions';\n\nexport async function generateKeyPair(): Promise<CryptoKeyPair> {\n await assertKeyGenerationIsAvailable();\n const keyPair = await crypto.subtle.generateKey(\n /* algorithm */ 'Ed25519', // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20\n /* extractable */ false, // Prevents the bytes of the private key from being visible to JS.\n /* allowed uses */ ['sign', 'verify']\n );\n return keyPair as CryptoKeyPair;\n}\n","import { assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\n\nexport type Ed25519Signature = Uint8Array & { readonly __brand: unique symbol };\n\nexport async function signBytes(key: CryptoKey, data: Uint8Array): Promise<Ed25519Signature> {\n await assertSigningCapabilityIsAvailable();\n const signedData = await crypto.subtle.sign('Ed25519', key, data);\n return new Uint8Array(signedData) as Ed25519Signature;\n}\n\nexport async function verifySignature(key: CryptoKey, signature: Ed25519Signature, data: Uint8Array): Promise<boolean> {\n await assertVerificationCapabilityIsAvailable();\n return await crypto.subtle.verify('Ed25519', key, signature, data);\n}\n"]}
|
|
@@ -2,10 +2,15 @@ this.globalThis = this.globalThis || {};
|
|
|
2
2
|
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
function n(){if(!globalThis.isSecureContext)throw new Error("Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts")}var e;async function y(t){return e===void 0&&(e=new Promise(o=>{t.generateKey("Ed25519",!1,["sign","verify"]).catch(()=>{o(e=!1);}).then(()=>{o(e=!0);});})),typeof e=="boolean"?e:await e}async function a(){if(n(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.generateKey!="function")throw new Error("No key generation implementation could be found");if(!await y(globalThis.crypto.subtle))throw new Error(`This runtime does not support the generation of Ed25519 key pairs.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
Install and import \`@solana/webcrypto-ed25519-polyfill\` before generating keys in environments that do not support Ed25519.
|
|
8
|
+
|
|
9
|
+
For a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20`)}async function s(){if(n(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.sign!="function")throw new Error("No signing implementation could be found")}async function l(){if(n(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.verify!="function")throw new Error("No signature verification implementation could be found")}async function d(){return await a(),await crypto.subtle.generateKey("Ed25519",!1,["sign","verify"])}async function m(t,o){await s();let r=await crypto.subtle.sign("Ed25519",t,o);return new Uint8Array(r)}async function w(t,o,r){return await l(),await crypto.subtle.verify("Ed25519",t,o,r)}
|
|
10
|
+
|
|
11
|
+
exports.generateKeyPair = d;
|
|
12
|
+
exports.signBytes = m;
|
|
13
|
+
exports.verifySignature = w;
|
|
9
14
|
|
|
10
15
|
return exports;
|
|
11
16
|
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type Ed25519Signature = Uint8Array & {
|
|
2
|
+
readonly __brand: unique symbol;
|
|
3
|
+
};
|
|
4
|
+
export declare function signBytes(key: CryptoKey, data: Uint8Array): Promise<Ed25519Signature>;
|
|
5
|
+
export declare function verifySignature(key: CryptoKey, signature: Ed25519Signature, data: Uint8Array): Promise<boolean>;
|
|
6
|
+
//# sourceMappingURL=signatures.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/keys",
|
|
3
|
-
"version": "2.0.0-experimental.
|
|
3
|
+
"version": "2.0.0-experimental.f040ea3",
|
|
4
4
|
"description": "Helpers for generating and transforming key material",
|
|
5
5
|
"exports": {
|
|
6
6
|
"browser": {
|
|
@@ -45,27 +45,29 @@
|
|
|
45
45
|
"supports bigint and not dead",
|
|
46
46
|
"maintained node versions"
|
|
47
47
|
],
|
|
48
|
+
"engine": {
|
|
49
|
+
"node": ">=17.4"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@solana/assertions": "2.0.0-experimental.f040ea3"
|
|
53
|
+
},
|
|
48
54
|
"devDependencies": {
|
|
49
|
-
"@solana/eslint-config-solana": "^1.0.
|
|
50
|
-
"@swc/
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"@typescript-eslint/
|
|
54
|
-
"@typescript-eslint/parser": "^5.57.1",
|
|
55
|
+
"@solana/eslint-config-solana": "^1.0.2",
|
|
56
|
+
"@swc/jest": "^0.2.28",
|
|
57
|
+
"@types/jest": "^29.5.5",
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
59
|
+
"@typescript-eslint/parser": "^6.3.0",
|
|
55
60
|
"agadoo": "^3.0.0",
|
|
56
|
-
"eslint": "^8.
|
|
57
|
-
"eslint-plugin-jest": "^27.
|
|
58
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
61
|
+
"eslint": "^8.45.0",
|
|
62
|
+
"eslint-plugin-jest": "^27.2.3",
|
|
59
63
|
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
60
|
-
"jest": "^29.
|
|
61
|
-
"jest-environment-jsdom": "^29.
|
|
64
|
+
"jest": "^29.7.0",
|
|
65
|
+
"jest-environment-jsdom": "^29.6.4",
|
|
62
66
|
"jest-runner-eslint": "^2.1.0",
|
|
63
67
|
"jest-runner-prettier": "^1.0.0",
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"tsup": "6.7.0",
|
|
68
|
-
"typescript": "^5.0.4",
|
|
68
|
+
"prettier": "^2.8",
|
|
69
|
+
"tsup": "7.2.0",
|
|
70
|
+
"typescript": "^5.2.2",
|
|
69
71
|
"version-from-git": "^1.1.1",
|
|
70
72
|
"build-scripts": "0.0.0",
|
|
71
73
|
"test-config": "0.0.0",
|
|
@@ -79,19 +81,17 @@
|
|
|
79
81
|
}
|
|
80
82
|
]
|
|
81
83
|
},
|
|
82
|
-
"dependencies": {
|
|
83
|
-
"bs58": "^5.0.0"
|
|
84
|
-
},
|
|
85
84
|
"scripts": {
|
|
86
85
|
"compile:js": "tsup --config build-scripts/tsup.config.library.ts",
|
|
87
86
|
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
|
|
88
87
|
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
89
88
|
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
|
|
89
|
+
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/*",
|
|
90
90
|
"test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
|
|
91
91
|
"test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
|
|
92
92
|
"test:treeshakability:browser": "agadoo dist/index.browser.js",
|
|
93
|
-
"test:treeshakability:native": "agadoo dist/index.
|
|
94
|
-
"test:treeshakability:node": "agadoo dist/index.
|
|
93
|
+
"test:treeshakability:native": "agadoo dist/index.native.js",
|
|
94
|
+
"test:treeshakability:node": "agadoo dist/index.node.js",
|
|
95
95
|
"test:typecheck": "tsc --noEmit",
|
|
96
96
|
"test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",
|
|
97
97
|
"test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent"
|
package/dist/types/base58.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type Base58EncodedAddress<TAddress extends string = string> = TAddress & {
|
|
2
|
-
readonly __base58EncodedAddress: unique symbol;
|
|
3
|
-
};
|
|
4
|
-
export declare function assertIsBase58EncodedAddress(putativeBase58EncodedAddress: string): asserts putativeBase58EncodedAddress is Base58EncodedAddress<typeof putativeBase58EncodedAddress>;
|
|
5
|
-
export declare function getBase58EncodedAddressComparator(): (x: string, y: string) => number;
|
|
6
|
-
//# sourceMappingURL=base58.d.ts.map
|