@t2000/sdk 8.0.1 → 8.1.0
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/dist/index.cjs +20 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { decodeSuiPrivateKey } from '@mysten/sui/cryptography';
|
|
|
11
11
|
import { access, mkdir, writeFile, readFile } from 'fs/promises';
|
|
12
12
|
import { join, dirname, resolve } from 'path';
|
|
13
13
|
import { homedir } from 'os';
|
|
14
|
+
import { ed25519 } from '@noble/curves/ed25519';
|
|
14
15
|
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
15
16
|
import { sha256 } from '@noble/hashes/sha256';
|
|
16
17
|
import { hexToBytes, bytesToHex } from '@noble/hashes/utils';
|
|
@@ -2074,7 +2075,24 @@ function jcs(value) {
|
|
|
2074
2075
|
function verifyReceiptSignature(receipt, signingKeyHex) {
|
|
2075
2076
|
try {
|
|
2076
2077
|
const sig = receipt.signature;
|
|
2077
|
-
if (sig?.
|
|
2078
|
+
if (!sig?.value) {
|
|
2079
|
+
return false;
|
|
2080
|
+
}
|
|
2081
|
+
const endorsed = hexToBytes(signingKeyHex.replace(/^0x/, ""));
|
|
2082
|
+
const sigBytes = hexToBytes(sig.value);
|
|
2083
|
+
if (sig.algo === "ed25519") {
|
|
2084
|
+
if (sigBytes.length !== 64 || endorsed.length !== 32) {
|
|
2085
|
+
return false;
|
|
2086
|
+
}
|
|
2087
|
+
const { value: _omitted, ...sigRest } = sig;
|
|
2088
|
+
const canonical2 = {
|
|
2089
|
+
...receipt,
|
|
2090
|
+
signature: sigRest
|
|
2091
|
+
};
|
|
2092
|
+
const msg = new TextEncoder().encode(jcs(canonical2));
|
|
2093
|
+
return ed25519.verify(sigBytes, msg, endorsed);
|
|
2094
|
+
}
|
|
2095
|
+
if (sig.algo !== "ecdsa-secp256k1") {
|
|
2078
2096
|
return false;
|
|
2079
2097
|
}
|
|
2080
2098
|
const canonical = {
|
|
@@ -2090,7 +2108,6 @@ function verifyReceiptSignature(receipt, signingKeyHex) {
|
|
|
2090
2108
|
signature: { algo: sig.algo, key_id: sig.key_id ?? "" }
|
|
2091
2109
|
};
|
|
2092
2110
|
const prehash = sha256(new TextEncoder().encode(jcs(canonical)));
|
|
2093
|
-
const sigBytes = hexToBytes(sig.value);
|
|
2094
2111
|
if (sigBytes.length !== 65) {
|
|
2095
2112
|
return false;
|
|
2096
2113
|
}
|
|
@@ -2102,8 +2119,7 @@ function verifyReceiptSignature(receipt, signingKeyHex) {
|
|
|
2102
2119
|
return false;
|
|
2103
2120
|
}
|
|
2104
2121
|
const recovered = secp256k1.Signature.fromCompact(sigBytes.slice(0, 64)).addRecoveryBit(v).recoverPublicKey(prehash).toHex(false);
|
|
2105
|
-
|
|
2106
|
-
return recovered.toLowerCase() === endorsed.toLowerCase();
|
|
2122
|
+
return recovered.toLowerCase() === bytesToHex(endorsed).toLowerCase();
|
|
2107
2123
|
} catch {
|
|
2108
2124
|
return false;
|
|
2109
2125
|
}
|