Skip to content
Closed
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
2 changes: 1 addition & 1 deletion modules/sdk-lib-mpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
]
},
"dependencies": {
"@bitgo/wasm-mps": "1.8.1",
"@bitgo/wasm-mps": "1.10.0",
"@noble/curves": "1.8.1",
"@silencelaboratories/dkls-wasm-ll-node": "1.2.0-pre.4",
"@silencelaboratories/dkls-wasm-ll-web": "1.2.0-pre.4",
Expand Down
32 changes: 25 additions & 7 deletions modules/sdk-lib-mpc/test/unit/tss/eddsa/derive.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import assert from 'assert';
import { ed25519 } from '@noble/curves/ed25519';
import { Ed25519Bip32HdTree } from '../../../../src/curves/ed25519Bip32HdTree';
import { bigIntFromBufferBE, bigIntFromBufferLE, bigIntToBufferBE, bigIntToBufferLE } from '../../../../src/util';
import { EddsaMPSDsg, MPSUtil } from '../../../../src/tss/eddsa-mps';
import { deriveUnhardenedMps } from '../../../../src/tss/eddsa-mps/derive';
import { generateEdDsaDKGKeyShares } from './util';

/**
* Derives a child public key from a common keychain using the Cardano BIP32-Ed25519
* formula (same as Eddsa.deriveUnhardened). Returns the 128-char hex common keychain
* (64-char pk + 64-char chaincode) that wasm-mps 1.10.0 now uses for key derivation.
*/
function deriveUnhardenedBip32(commonKeychainHex: string, path: string): string {
const buf = Buffer.from(commonKeychainHex, 'hex');
const keychain = {
pk: bigIntFromBufferLE(buf.subarray(0, 32)),
chaincode: bigIntFromBufferBE(buf.subarray(32, 64)),
};
const hdTree = new Ed25519Bip32HdTree();
const derived = hdTree.publicDerive(keychain, path);
return bigIntToBufferLE(derived.pk, 32).toString('hex') + bigIntToBufferBE(derived.chaincode, 32).toString('hex');
}

const MESSAGE = Buffer.from('The Times 03/Jan/2009 Chancellor on brink of second bailout for banks');

describe('deriveUnhardenedMps', function () {
Expand Down Expand Up @@ -63,7 +81,7 @@ describe('deriveUnhardenedMps', function () {
});
});

describe('DSG signature cross-check against the public key derived by deriveUnhardenedMps', function () {
describe('DSG signature cross-check against the public key derived by BIP32 (deriveUnhardenedBip32)', function () {
let sigAtRoot: Buffer;
let sigAtM0: Buffer;
let sigAtM01: Buffer;
Expand All @@ -86,19 +104,19 @@ describe('deriveUnhardenedMps', function () {
assert(ed25519.verify(sigAtRoot, MESSAGE, rootPubKey), 'DSG at "m" should verify against the raw DKG public key');
});

it('signature from DSG at "m/0" verifies against deriveUnhardenedMps(commonKeychain, "m/0")', function () {
const derivedPk = Buffer.from(deriveUnhardenedMps(commonKeychain, 'm/0').slice(0, 64), 'hex');
it('signature from DSG at "m/0" verifies against deriveUnhardenedBip32(commonKeychain, "m/0")', function () {
const derivedPk = Buffer.from(deriveUnhardenedBip32(commonKeychain, 'm/0').slice(0, 64), 'hex');
assert(
ed25519.verify(sigAtM0, MESSAGE, derivedPk),
'DSG at "m/0" should verify against deriveUnhardenedMps result at "m/0"'
'DSG at "m/0" should verify against BIP32-derived public key at "m/0"'
);
});

it('signature from DSG at "m/0/1" verifies against deriveUnhardenedMps(commonKeychain, "m/0/1")', function () {
const derivedPk = Buffer.from(deriveUnhardenedMps(commonKeychain, 'm/0/1').slice(0, 64), 'hex');
it('signature from DSG at "m/0/1" verifies against deriveUnhardenedBip32(commonKeychain, "m/0/1")', function () {
const derivedPk = Buffer.from(deriveUnhardenedBip32(commonKeychain, 'm/0/1').slice(0, 64), 'hex');
assert(
ed25519.verify(sigAtM01, MESSAGE, derivedPk),
'DSG at "m/0/1" should verify against deriveUnhardenedMps result at "m/0/1"'
'DSG at "m/0/1" should verify against BIP32-derived public key at "m/0/1"'
);
});
});
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1013,10 +1013,10 @@
resolved "https://registry.npmjs.org/@bitgo/wasm-dot/-/wasm-dot-1.7.0.tgz"
integrity sha512-KoXavJvyDHlEN+sWcigbgxYJtdFaU7gS0EkYQbNH4npVjNlzo6rL6gwjyWbyOy7oEs65DhpJ9vY5kRbE/bKiTQ==

"@bitgo/wasm-mps@1.8.1":
version "1.8.1"
resolved "https://registry.npmjs.org/@bitgo/wasm-mps/-/wasm-mps-1.8.1.tgz#946673f5845696cdcf744f8122fd1fc2be3edce1"
integrity sha512-CV8EXYc1BGYtXdCRDxJ5h04nj/LpMgu3VlkfowlodI6UKcj1zotAvk4OMIdgiPPbKVr1l+xibHDXZYx/uf3rnw==
"@bitgo/wasm-mps@1.10.0":
version "1.10.0"
resolved "https://registry.npmjs.org/@bitgo/wasm-mps/-/wasm-mps-1.10.0.tgz#df6a056247ce04c7d92369d257b659876e03261d"
integrity sha512-f42sMCyqqlaId3AtcvdpOfR+mOjAyVopCxCCAqW7wcTAQ8ZBS9rMGQIzTMiqFmZDBMWsAe+QHWA6XseIuzTVdQ==

"@bitgo/wasm-solana@^2.6.0":
version "2.6.0"
Expand Down
Loading