@mysten/signers 0.1.11 → 0.1.13
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/CHANGELOG.md +13 -0
- package/dist/cjs/webcrypto/index.d.ts +14 -0
- package/dist/cjs/webcrypto/index.js +83 -0
- package/dist/cjs/webcrypto/index.js.map +7 -0
- package/dist/esm/webcrypto/index.d.ts +14 -0
- package/dist/esm/webcrypto/index.js +63 -0
- package/dist/esm/webcrypto/index.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -3
- package/src/webcrypto/index.ts +69 -0
- package/webcrypto/package.json +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mysten/signers",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "A collection of KMS signers for various cloud providers",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Mysten Labs <build@mystenlabs.com>",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"./gcp": {
|
|
14
14
|
"import": "./dist/esm/gcp/index.js",
|
|
15
15
|
"require": "./dist/cjs/gcp/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./webcrypto": {
|
|
18
|
+
"import": "./dist/esm/webcrypto/index.js",
|
|
19
|
+
"require": "./dist/cjs/webcrypto/index.js"
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"sideEffects": false,
|
|
@@ -23,7 +27,8 @@
|
|
|
23
27
|
"aws",
|
|
24
28
|
"dist",
|
|
25
29
|
"gcp",
|
|
26
|
-
"src"
|
|
30
|
+
"src",
|
|
31
|
+
"webcrypto"
|
|
27
32
|
],
|
|
28
33
|
"repository": {
|
|
29
34
|
"type": "git",
|
|
@@ -45,7 +50,7 @@
|
|
|
45
50
|
"@noble/curves": "^1.4.2",
|
|
46
51
|
"@noble/hashes": "^1.4.0",
|
|
47
52
|
"asn1-ts": "^8.0.2",
|
|
48
|
-
"@mysten/sui": "1.
|
|
53
|
+
"@mysten/sui": "1.24.0"
|
|
49
54
|
},
|
|
50
55
|
"engines": {
|
|
51
56
|
"node": ">=20"
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { SignatureScheme } from '@mysten/sui/cryptography';
|
|
5
|
+
import { Signer } from '@mysten/sui/cryptography';
|
|
6
|
+
import { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';
|
|
7
|
+
|
|
8
|
+
// Convert from uncompressed (65 bytes) to compressed (33 bytes) format
|
|
9
|
+
function getCompressedPublicKey(publicKey: Uint8Array) {
|
|
10
|
+
const rawBytes = new Uint8Array(publicKey);
|
|
11
|
+
const x = rawBytes.slice(1, 33);
|
|
12
|
+
const y = rawBytes.slice(33, 65);
|
|
13
|
+
|
|
14
|
+
const prefix = (y[31] & 1) === 0 ? 0x02 : 0x03;
|
|
15
|
+
|
|
16
|
+
const compressed = new Uint8Array(Secp256r1PublicKey.SIZE);
|
|
17
|
+
compressed[0] = prefix;
|
|
18
|
+
compressed.set(x, 1);
|
|
19
|
+
|
|
20
|
+
return compressed;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class WebCryptoSigner extends Signer {
|
|
24
|
+
privateKey: CryptoKey;
|
|
25
|
+
|
|
26
|
+
#publicKey: Secp256r1PublicKey;
|
|
27
|
+
|
|
28
|
+
static async generate({ extractable = false }: { extractable?: boolean } = {}) {
|
|
29
|
+
const keypair = await globalThis.crypto.subtle.generateKey(
|
|
30
|
+
{
|
|
31
|
+
name: 'ECDSA',
|
|
32
|
+
namedCurve: 'P-256',
|
|
33
|
+
},
|
|
34
|
+
extractable,
|
|
35
|
+
['sign', 'verify'],
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const publicKey = await globalThis.crypto.subtle.exportKey('raw', keypair.publicKey);
|
|
39
|
+
|
|
40
|
+
return new WebCryptoSigner(keypair.privateKey, new Uint8Array(publicKey));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getKeyScheme(): SignatureScheme {
|
|
44
|
+
return 'Secp256r1';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
constructor(privateKey: CryptoKey, publicKey: Uint8Array) {
|
|
48
|
+
super();
|
|
49
|
+
this.privateKey = privateKey;
|
|
50
|
+
this.#publicKey = new Secp256r1PublicKey(getCompressedPublicKey(publicKey));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getPublicKey() {
|
|
54
|
+
return this.#publicKey;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async sign(bytes: Uint8Array): Promise<Uint8Array> {
|
|
58
|
+
const signature = await globalThis.crypto.subtle.sign(
|
|
59
|
+
{
|
|
60
|
+
name: 'ECDSA',
|
|
61
|
+
hash: 'SHA-256',
|
|
62
|
+
},
|
|
63
|
+
this.privateKey,
|
|
64
|
+
bytes,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return new Uint8Array(signature);
|
|
68
|
+
}
|
|
69
|
+
}
|