Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 7 additions & 26 deletions docs/sbom/coreguard-0.1.0.cdx.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"bomFormat": "CycloneDX",
"specVersion": "1.5",
"serialNumber": "urn:uuid:5d55c919-b9c6-86a7-8b7a-cb0439db44ee",
"serialNumber": "urn:uuid:76b71079-7f06-1499-62d4-0e1e40e6d928",
"version": 1,
"metadata": {
"tools": [
Expand Down Expand Up @@ -365,12 +365,12 @@
{
"type": "library",
"name": "@noble/curves",
"version": "1.9.7",
"purl": "pkg:npm/%40noble/curves@1.9.7",
"version": "2.4.0",
"purl": "pkg:npm/%40noble/curves@2.4.0",
"hashes": [
{
"alg": "SHA-512",
"content": "81b286711518223037ff308235a5837224cc148d1d0a4be8bb74cbf199b2e4d73bb09e3b6b48ed39e6684da33192ea91a3d71186339d6495de831604e4537fc7"
"content": "3f8ffadb3ae07c7df70a7784dc39f85a1255036d98514d1e479d702886a7e0d551bf0b00d189cf4f0586a4d6e9b9a712ba399214bbf2ce9cae477d3e7dbab613"
}
],
"licenses": [
Expand Down Expand Up @@ -403,12 +403,12 @@
{
"type": "library",
"name": "@noble/hashes",
"version": "1.8.0",
"purl": "pkg:npm/%40noble/hashes@1.8.0",
"version": "2.4.0",
"purl": "pkg:npm/%40noble/hashes@2.4.0",
"hashes": [
{
"alg": "SHA-512",
"content": "8c2b3d95d77b370ce98170c87fa3f7f8dac787dfec0fa0907711f28d023e87feab0cda3cf32a41c71cf8e540ee647cfdaf7b4dcfb37f5489d256855db57108e0"
"content": "5f95da5566480424fb1c76469b923b6505c3c0b1be6c65ee4ab310016fbb66f97cee1d6499cd5907555244972951fa14ac6429e05928c66e6467e32cf9a5be78"
}
],
"licenses": [
Expand Down Expand Up @@ -438,25 +438,6 @@
}
]
},
{
"type": "library",
"name": "@stellar/stellar-sdk/node_modules/@noble/hashes",
"version": "2.4.0",
"purl": "pkg:npm/%40stellar/stellar-sdk/node_modules/@noble/hashes@2.4.0",
"hashes": [
{
"alg": "SHA-512",
"content": "5f95da5566480424fb1c76469b923b6505c3c0b1be6c65ee4ab310016fbb66f97cee1d6499cd5907555244972951fa14ac6429e05928c66e6467e32cf9a5be78"
}
],
"licenses": [
{
"license": {
"id": "MIT"
}
}
]
},
{
"type": "library",
"name": "@stellar/stellar-sdk",
Expand Down
34 changes: 11 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/evm/keccak256.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Everything else in @coreguard/evm imports keccak from here (or bytes.js).
*/

import { keccak_256 } from "@noble/hashes/sha3";
import { keccak_256 } from "@noble/hashes/sha3.js";
import { asBytes } from "./bytes.js";

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"node": ">=18"
},
"dependencies": {
"@noble/curves": "^1.9.0",
"@noble/hashes": "^1.8.0"
"@noble/curves": "^2.4.0",
"@noble/hashes": "^2.4.0"
},
"publishConfig": {
"access": "public"
Expand Down
26 changes: 16 additions & 10 deletions packages/evm/signer/secp256k1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
* and public-key recovery (the EIP-712 verifier primitive).
*/

import { secp256k1 } from "@noble/curves/secp256k1";
import { secp256k1 } from "@noble/curves/secp256k1.js";
import { bytesToHex, hexToBytes, asBytes, concat } from "../bytes.js";
import { keccak } from "../keccak256.js";
import { addressFromPublicKey } from "./address.js";

/** secp256k1 group order (n) — the scalar field order. */
const CURVE_ORDER = secp256k1.Point.CURVE().n;

/** 32-byte big-endian encoding of a 256-bit value. */
export function to32(value) {
const bytes = hexToBytes(Buffer.from(BigInt(value).toString(16).padStart(64, "0"), "hex"));
Expand All @@ -35,15 +38,15 @@ export function recoverSignerAddress(digest, sig) {
const { r, s, v } = sig || {};
const rBig = BigInt(typeof r === "bigint" ? r : "0x" + String(r || ""));
const sBig = BigInt(typeof s === "bigint" ? s : "0x" + String(s || ""));
if (rBig <= 0n || rBig >= secp256k1.CURVE.n) throw new Error("recover: r out of range");
if (sBig <= 0n || sBig >= secp256k1.CURVE.n) throw new Error("recover: s out of range");
if (rBig <= 0n || rBig >= CURVE_ORDER) throw new Error("recover: r out of range");
if (sBig <= 0n || sBig >= CURVE_ORDER) throw new Error("recover: s out of range");
const recid = Number(v) % 27;
if (recid > 1) throw new Error("recover: v must be 27 or 28");

const compact = concat(to32(rBig), to32(sBig));
const sigObj = secp256k1.Signature.fromBytes(compact).addRecoveryBit(recid);
const sigObj = secp256k1.Signature.fromBytes(compact, "compact").addRecoveryBit(recid);
const pub = sigObj.recoverPublicKey(asBytes(digest));
return addressFromPublicKey(pub.toRawBytes(false));
return addressFromPublicKey(pub.toBytes(false));
}

/**
Expand All @@ -55,11 +58,14 @@ export async function signDigest(digestBytes, privateKeyHex) {
const priv = typeof privateKeyHex === "string"
? hexToBytes(privateKeyHex)
: privateKeyHex;
const sig = secp256k1.sign(asBytes(digestBytes), priv, { prehash: false });
const recid = sig.recovery;
const compact = sig.toCompactRawBytes();
const r = bytesToHex(compact.slice(0, 32));
const s = bytesToHex(compact.slice(32));
// noble/curves v2 returns encoded bytes; "recovered" is 65 bytes:
// recovery byte ‖ r(32) ‖ s(32).
const recovered = secp256k1.sign(asBytes(digestBytes), priv, { prehash: false, format: "recovered" });
const recid = recovered[0];
if (recid > 1) throw new Error("sign: recovery id outside the Ethereum v=27/28 range");
const compact = recovered.subarray(1);
const r = bytesToHex(compact.subarray(0, 32));
const s = bytesToHex(compact.subarray(32, 64));
return { r, s, v: 27 + recid };
}

Expand Down
Loading