space-data-module-sdk 0.9.4 → 0.9.5
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/package.json +1 -1
- package/src/auth/permissions.js +13 -1
- package/src/compiler/compileModule.js +3 -2
- package/src/host/browserHost.js +8 -19
- package/src/host/hostWorkerBundleSources.js +3 -3
- package/src/host/nodeHost.js +11 -10
- package/src/host/sabHostcallChannel.js +3 -0
- package/src/host/typedDispatch.js +4 -2
- package/src/index.d.ts +2 -0
- package/src/utils/wasmCrypto.js +56 -9
package/package.json
CHANGED
package/src/auth/permissions.js
CHANGED
|
@@ -52,6 +52,14 @@ export async function createDeploymentAuthorization(options = {}) {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// Authorization signatures ("secp256k1-sha256"): ECDSA over sha256(canonical bytes), hashed exactly once; the
|
|
56
|
+
// signature is 64 raw bytes (r || s). node:crypto verifies it with crypto.verify("sha256", bytes, ...).
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A signer for authorizations: `signDigest(digest)` signs the 32-byte sha256 of the canonical bytes AS GIVEN, with no
|
|
60
|
+
* further hashing - e.g. hd-wallet-wasm's secp256k1.signRecoverable(digest, key).signature, or the SDK's
|
|
61
|
+
* secp256k1SignDigest. Never hd-wallet-wasm's secp256k1.sign(digest): it hashes its input again.
|
|
62
|
+
*/
|
|
55
63
|
export function createHdWalletSigner(options = {}) {
|
|
56
64
|
if (typeof options.signDigest !== "function") {
|
|
57
65
|
throw new Error("createHdWalletSigner requires signDigest.");
|
|
@@ -73,6 +81,10 @@ export function createHdWalletSigner(options = {}) {
|
|
|
73
81
|
};
|
|
74
82
|
}
|
|
75
83
|
|
|
84
|
+
/**
|
|
85
|
+
* A verifier for authorizations: `verifyDigest(digest, signature, header, payload)` checks a signature over the
|
|
86
|
+
* 32-byte sha256 of the canonical bytes AS GIVEN, with no further hashing (e.g. the SDK's secp256k1VerifyDigest).
|
|
87
|
+
*/
|
|
76
88
|
export function createHdWalletVerifier(options = {}) {
|
|
77
89
|
if (typeof options.verifyDigest !== "function") {
|
|
78
90
|
throw new Error("createHdWalletVerifier requires verifyDigest.");
|
|
@@ -80,7 +92,7 @@ export function createHdWalletVerifier(options = {}) {
|
|
|
80
92
|
return {
|
|
81
93
|
async verify(bytes, signature, header, payload) {
|
|
82
94
|
const digest = await sha256Bytes(bytes);
|
|
83
|
-
return options.verifyDigest(digest, signature, header, payload);
|
|
95
|
+
return Boolean(await options.verifyDigest(digest, signature, header, payload));
|
|
84
96
|
},
|
|
85
97
|
};
|
|
86
98
|
}
|
|
@@ -1397,11 +1397,12 @@ export async function protectModuleArtifact(options = {}) {
|
|
|
1397
1397
|
publicKeyHex: bytesToHex(identity.signingKey.publicKey),
|
|
1398
1398
|
derivationPath: identity.signingKey.path,
|
|
1399
1399
|
keyId: artifactId,
|
|
1400
|
+
// the digest as given: signRecoverable signs its 32-byte input, secp256k1.sign would hash it again
|
|
1400
1401
|
async signDigest(digest) {
|
|
1401
|
-
return identity.wallet.curves.secp256k1.
|
|
1402
|
+
return identity.wallet.curves.secp256k1.signRecoverable(
|
|
1402
1403
|
digest,
|
|
1403
1404
|
identity.signingKey.privateKey,
|
|
1404
|
-
);
|
|
1405
|
+
).signature;
|
|
1405
1406
|
},
|
|
1406
1407
|
});
|
|
1407
1408
|
|
package/src/host/browserHost.js
CHANGED
|
@@ -316,7 +316,7 @@ async function keyslotSign(walletSignAdapter, wasmWallet, params = {}) {
|
|
|
316
316
|
}
|
|
317
317
|
|
|
318
318
|
if (algorithm === "secp256k1") {
|
|
319
|
-
if (!wasmWallet?.
|
|
319
|
+
if (!wasmWallet?.curves?.secp256k1?.sign) {
|
|
320
320
|
throw new Error(
|
|
321
321
|
"Browser host keyslot.sign requires a preloaded wasmWallet.",
|
|
322
322
|
);
|
|
@@ -326,9 +326,9 @@ async function keyslotSign(walletSignAdapter, wasmWallet, params = {}) {
|
|
|
326
326
|
`keyslot "${slotId}" is not a 32-byte secp256k1 private key`,
|
|
327
327
|
);
|
|
328
328
|
}
|
|
329
|
-
|
|
329
|
+
// ECDSA over sha256(payload), as the Go node: the wallet's sign hashes once.
|
|
330
330
|
const rawSignature = new Uint8Array(
|
|
331
|
-
wasmWallet.curves.secp256k1.sign(
|
|
331
|
+
wasmWallet.curves.secp256k1.sign(payload, keyMaterial),
|
|
332
332
|
);
|
|
333
333
|
return {
|
|
334
334
|
signature: bytesToBase64(rawSignatureToDer(rawSignature)),
|
|
@@ -918,37 +918,26 @@ export class BrowserHost {
|
|
|
918
918
|
},
|
|
919
919
|
sign: (message, privateKey) => {
|
|
920
920
|
this.#assertCapability("crypto_sign", "crypto.secp256k1.sign");
|
|
921
|
-
if (
|
|
922
|
-
!wasmWallet?.utils?.sha256 ||
|
|
923
|
-
!wasmWallet?.curves?.secp256k1?.sign
|
|
924
|
-
) {
|
|
921
|
+
if (!wasmWallet?.curves?.secp256k1?.sign) {
|
|
925
922
|
throw new Error(
|
|
926
923
|
"Browser host crypto.secp256k1.sign requires a preloaded wasmWallet.",
|
|
927
924
|
);
|
|
928
925
|
}
|
|
929
|
-
|
|
930
|
-
wasmWallet.utils.sha256(toUint8Array(message)),
|
|
931
|
-
);
|
|
926
|
+
// ECDSA over sha256(message): the wallet's sign hashes once
|
|
932
927
|
const rawSignature = new Uint8Array(
|
|
933
|
-
wasmWallet.curves.secp256k1.sign(
|
|
928
|
+
wasmWallet.curves.secp256k1.sign(toUint8Array(message), toUint8Array(privateKey)),
|
|
934
929
|
);
|
|
935
930
|
return rawSignatureToDer(rawSignature);
|
|
936
931
|
},
|
|
937
932
|
verify: (message, signature, publicKey) => {
|
|
938
933
|
this.#assertCapability("crypto_verify", "crypto.secp256k1.verify");
|
|
939
|
-
if (
|
|
940
|
-
!wasmWallet?.utils?.sha256 ||
|
|
941
|
-
!wasmWallet?.curves?.secp256k1?.verify
|
|
942
|
-
) {
|
|
934
|
+
if (!wasmWallet?.curves?.secp256k1?.verify) {
|
|
943
935
|
throw new Error(
|
|
944
936
|
"Browser host crypto.secp256k1.verify requires a preloaded wasmWallet.",
|
|
945
937
|
);
|
|
946
938
|
}
|
|
947
|
-
const digest = new Uint8Array(
|
|
948
|
-
wasmWallet.utils.sha256(toUint8Array(message)),
|
|
949
|
-
);
|
|
950
939
|
const result = wasmWallet.curves.secp256k1.verify(
|
|
951
|
-
|
|
940
|
+
toUint8Array(message),
|
|
952
941
|
derSignatureToRaw(signature),
|
|
953
942
|
toUint8Array(publicKey),
|
|
954
943
|
);
|