@solana/keys 2.0.0-experimental.fbdf21a → 2.0.0-experimental.fc4e943
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +30 -21
- package/dist/index.browser.cjs +26 -32
- 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 +78 -102
- 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 -32
- 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 +20 -20
- package/dist/types/base58.d.ts +0 -6
- package/dist/types/base58.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
package/LICENSE
CHANGED
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,40 +1,34 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var assertions = require('@solana/assertions');
|
|
4
4
|
|
|
5
|
-
// src/
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
} catch (e) {
|
|
21
|
-
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
22
|
-
cause: e
|
|
23
|
-
});
|
|
24
|
-
}
|
|
5
|
+
// src/key-pair.ts
|
|
6
|
+
async function generateKeyPair() {
|
|
7
|
+
await assertions.assertKeyGenerationIsAvailable();
|
|
8
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
9
|
+
/* algorithm */
|
|
10
|
+
"Ed25519",
|
|
11
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
12
|
+
/* extractable */
|
|
13
|
+
false,
|
|
14
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
15
|
+
/* allowed uses */
|
|
16
|
+
["sign", "verify"]
|
|
17
|
+
);
|
|
18
|
+
return keyPair;
|
|
25
19
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}).compare;
|
|
20
|
+
async function signBytes(key, data) {
|
|
21
|
+
await assertions.assertSigningCapabilityIsAvailable();
|
|
22
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
23
|
+
return new Uint8Array(signedData);
|
|
24
|
+
}
|
|
25
|
+
async function verifySignature(key, signature, data) {
|
|
26
|
+
await assertions.assertVerificationCapabilityIsAvailable();
|
|
27
|
+
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
35
28
|
}
|
|
36
29
|
|
|
37
|
-
exports.
|
|
38
|
-
exports.
|
|
30
|
+
exports.generateKeyPair = generateKeyPair;
|
|
31
|
+
exports.signBytes = signBytes;
|
|
32
|
+
exports.verifySignature = verifySignature;
|
|
39
33
|
//# sourceMappingURL=out.js.map
|
|
40
34
|
//# sourceMappingURL=index.browser.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
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,114 +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
|
-
|
|
12
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
|
|
13
|
-
var InvalidBaseStringError = class extends Error {
|
|
14
|
-
constructor(value, base, cause) {
|
|
15
|
-
const message = `Expected a string of base ${base}, got [${value}].`;
|
|
16
|
-
super(message);
|
|
17
|
-
__publicField(this, "name", "InvalidBaseStringError");
|
|
18
|
-
this.cause = cause;
|
|
5
|
+
// ../assertions/dist/index.browser.js
|
|
6
|
+
function assertIsSecureContext() {
|
|
7
|
+
if (!globalThis.isSecureContext) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
|
|
10
|
+
);
|
|
19
11
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return new Uint8Array();
|
|
36
|
-
const chars = [...value];
|
|
37
|
-
let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
|
|
38
|
-
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
39
|
-
const leadingZeroes = Array(trailIndex).fill(0);
|
|
40
|
-
if (trailIndex === chars.length)
|
|
41
|
-
return Uint8Array.from(leadingZeroes);
|
|
42
|
-
const tailChars = chars.slice(trailIndex);
|
|
43
|
-
let base10Number = 0n;
|
|
44
|
-
let baseXPower = 1n;
|
|
45
|
-
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
46
|
-
base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
|
|
47
|
-
baseXPower *= baseBigInt;
|
|
48
|
-
}
|
|
49
|
-
const tailBytes = [];
|
|
50
|
-
while (base10Number > 0n) {
|
|
51
|
-
tailBytes.unshift(Number(base10Number % 256n));
|
|
52
|
-
base10Number /= 256n;
|
|
53
|
-
}
|
|
54
|
-
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
55
|
-
},
|
|
56
|
-
deserialize(buffer, offset = 0) {
|
|
57
|
-
if (buffer.length === 0)
|
|
58
|
-
return ["", 0];
|
|
59
|
-
const bytes = buffer.slice(offset);
|
|
60
|
-
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
61
|
-
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
62
|
-
const leadingZeroes = alphabet[0].repeat(trailIndex);
|
|
63
|
-
if (trailIndex === bytes.length)
|
|
64
|
-
return [leadingZeroes, buffer.length];
|
|
65
|
-
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
66
|
-
const tailChars = [];
|
|
67
|
-
while (base10Number > 0n) {
|
|
68
|
-
tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
|
|
69
|
-
base10Number /= baseBigInt;
|
|
70
|
-
}
|
|
71
|
-
return [leadingZeroes + tailChars.join(""), buffer.length];
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
|
|
77
|
-
var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
78
|
-
|
|
79
|
-
// src/base58.ts
|
|
80
|
-
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
81
|
-
try {
|
|
82
|
-
if (
|
|
83
|
-
// Lowest address (32 bytes of zeroes)
|
|
84
|
-
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
85
|
-
putativeBase58EncodedAddress.length > 44
|
|
86
|
-
) {
|
|
87
|
-
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
88
|
-
}
|
|
89
|
-
const bytes = base58.serialize(putativeBase58EncodedAddress);
|
|
90
|
-
const numBytes = bytes.byteLength;
|
|
91
|
-
if (numBytes !== 32) {
|
|
92
|
-
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
93
|
-
}
|
|
94
|
-
} catch (e) {
|
|
95
|
-
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
96
|
-
cause: e
|
|
12
|
+
}
|
|
13
|
+
var cachedEd25519Decision;
|
|
14
|
+
async function isEd25519CurveSupported(subtle) {
|
|
15
|
+
if (cachedEd25519Decision === void 0) {
|
|
16
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
17
|
+
subtle.generateKey(
|
|
18
|
+
"Ed25519",
|
|
19
|
+
/* extractable */
|
|
20
|
+
false,
|
|
21
|
+
["sign", "verify"]
|
|
22
|
+
).catch(() => {
|
|
23
|
+
resolve(cachedEd25519Decision = false);
|
|
24
|
+
}).then(() => {
|
|
25
|
+
resolve(cachedEd25519Decision = true);
|
|
26
|
+
});
|
|
97
27
|
});
|
|
98
28
|
}
|
|
29
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
30
|
+
return cachedEd25519Decision;
|
|
31
|
+
} else {
|
|
32
|
+
return await cachedEd25519Decision;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function assertKeyGenerationIsAvailable() {
|
|
36
|
+
assertIsSecureContext();
|
|
37
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
38
|
+
throw new Error("No key generation implementation could be found");
|
|
39
|
+
}
|
|
40
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function assertSigningCapabilityIsAvailable() {
|
|
47
|
+
assertIsSecureContext();
|
|
48
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
49
|
+
throw new Error("No signing implementation could be found");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function assertVerificationCapabilityIsAvailable() {
|
|
53
|
+
assertIsSecureContext();
|
|
54
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
|
|
55
|
+
throw new Error("No signature verification implementation could be found");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/key-pair.ts
|
|
60
|
+
async function generateKeyPair() {
|
|
61
|
+
await assertKeyGenerationIsAvailable();
|
|
62
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
63
|
+
/* algorithm */
|
|
64
|
+
"Ed25519",
|
|
65
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
66
|
+
/* extractable */
|
|
67
|
+
false,
|
|
68
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
69
|
+
/* allowed uses */
|
|
70
|
+
["sign", "verify"]
|
|
71
|
+
);
|
|
72
|
+
return keyPair;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/signatures.ts
|
|
76
|
+
async function signBytes(key, data) {
|
|
77
|
+
await assertSigningCapabilityIsAvailable();
|
|
78
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
79
|
+
return new Uint8Array(signedData);
|
|
99
80
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
ignorePunctuation: false,
|
|
104
|
-
localeMatcher: "best fit",
|
|
105
|
-
numeric: false,
|
|
106
|
-
sensitivity: "variant",
|
|
107
|
-
usage: "sort"
|
|
108
|
-
}).compare;
|
|
81
|
+
async function verifySignature(key, signature, data) {
|
|
82
|
+
await assertVerificationCapabilityIsAvailable();
|
|
83
|
+
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
109
84
|
}
|
|
110
85
|
|
|
111
|
-
exports.
|
|
112
|
-
exports.
|
|
86
|
+
exports.generateKeyPair = generateKeyPair;
|
|
87
|
+
exports.signBytes = signBytes;
|
|
88
|
+
exports.verifySignature = verifySignature;
|
|
113
89
|
|
|
114
90
|
return exports;
|
|
115
91
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
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,40 +1,34 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var assertions = require('@solana/assertions');
|
|
4
4
|
|
|
5
|
-
// src/
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
} catch (e) {
|
|
21
|
-
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
22
|
-
cause: e
|
|
23
|
-
});
|
|
24
|
-
}
|
|
5
|
+
// src/key-pair.ts
|
|
6
|
+
async function generateKeyPair() {
|
|
7
|
+
await assertions.assertKeyGenerationIsAvailable();
|
|
8
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
9
|
+
/* algorithm */
|
|
10
|
+
"Ed25519",
|
|
11
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
12
|
+
/* extractable */
|
|
13
|
+
false,
|
|
14
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
15
|
+
/* allowed uses */
|
|
16
|
+
["sign", "verify"]
|
|
17
|
+
);
|
|
18
|
+
return keyPair;
|
|
25
19
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}).compare;
|
|
20
|
+
async function signBytes(key, data) {
|
|
21
|
+
await assertions.assertSigningCapabilityIsAvailable();
|
|
22
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
23
|
+
return new Uint8Array(signedData);
|
|
24
|
+
}
|
|
25
|
+
async function verifySignature(key, signature, data) {
|
|
26
|
+
await assertions.assertVerificationCapabilityIsAvailable();
|
|
27
|
+
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
35
28
|
}
|
|
36
29
|
|
|
37
|
-
exports.
|
|
38
|
-
exports.
|
|
30
|
+
exports.generateKeyPair = generateKeyPair;
|
|
31
|
+
exports.signBytes = signBytes;
|
|
32
|
+
exports.verifySignature = verifySignature;
|
|
39
33
|
//# sourceMappingURL=out.js.map
|
|
40
34
|
//# sourceMappingURL=index.node.cjs.map
|
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.fc4e943",
|
|
4
4
|
"description": "Helpers for generating and transforming key material",
|
|
5
5
|
"exports": {
|
|
6
6
|
"browser": {
|
|
@@ -45,30 +45,29 @@
|
|
|
45
45
|
"supports bigint and not dead",
|
|
46
46
|
"maintained node versions"
|
|
47
47
|
],
|
|
48
|
+
"engine": {
|
|
49
|
+
"node": ">=17.4"
|
|
50
|
+
},
|
|
48
51
|
"dependencies": {
|
|
49
|
-
"@
|
|
52
|
+
"@solana/assertions": "2.0.0-experimental.fc4e943"
|
|
50
53
|
},
|
|
51
54
|
"devDependencies": {
|
|
52
|
-
"@solana/eslint-config-solana": "^1.0.
|
|
53
|
-
"@swc/
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"@typescript-eslint/
|
|
57
|
-
"@typescript-eslint/parser": "^5.57.1",
|
|
55
|
+
"@solana/eslint-config-solana": "^1.0.2",
|
|
56
|
+
"@swc/jest": "^0.2.28",
|
|
57
|
+
"@types/jest": "^29.5.5",
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
59
|
+
"@typescript-eslint/parser": "^6.3.0",
|
|
58
60
|
"agadoo": "^3.0.0",
|
|
59
|
-
"eslint": "^8.
|
|
60
|
-
"eslint-plugin-jest": "^27.
|
|
61
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
61
|
+
"eslint": "^8.45.0",
|
|
62
|
+
"eslint-plugin-jest": "^27.2.3",
|
|
62
63
|
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
63
|
-
"jest": "^29.
|
|
64
|
-
"jest-environment-jsdom": "^29.
|
|
64
|
+
"jest": "^29.7.0",
|
|
65
|
+
"jest-environment-jsdom": "^29.6.4",
|
|
65
66
|
"jest-runner-eslint": "^2.1.0",
|
|
66
67
|
"jest-runner-prettier": "^1.0.0",
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"tsup": "6.7.0",
|
|
71
|
-
"typescript": "^5.0.4",
|
|
68
|
+
"prettier": "^2.8",
|
|
69
|
+
"tsup": "7.2.0",
|
|
70
|
+
"typescript": "^5.2.2",
|
|
72
71
|
"version-from-git": "^1.1.1",
|
|
73
72
|
"build-scripts": "0.0.0",
|
|
74
73
|
"test-config": "0.0.0",
|
|
@@ -87,11 +86,12 @@
|
|
|
87
86
|
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
|
|
88
87
|
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
89
88
|
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
|
|
89
|
+
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
|
|
90
90
|
"test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
|
|
91
91
|
"test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
|
|
92
92
|
"test:treeshakability:browser": "agadoo dist/index.browser.js",
|
|
93
|
-
"test:treeshakability:native": "agadoo dist/index.
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base58.d.ts","sourceRoot":"","sources":["../../src/base58.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,oBAAoB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,QAAQ,GAAG;IAC5E,QAAQ,CAAC,sBAAsB,EAAE,OAAO,MAAM,CAAC;CAClD,CAAC;AAEF,wBAAgB,4BAA4B,CACxC,4BAA4B,EAAE,MAAM,GACrC,OAAO,CAAC,4BAA4B,IAAI,oBAAoB,CAAC,OAAO,4BAA4B,CAAC,CAsBnG;AAED,wBAAgB,iCAAiC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CASpF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|