Skip to content

Commit

Permalink
chore: using bb ecdsa
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jul 4, 2023
1 parent ba1a16d commit 570518d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 22 deletions.
1 change: 0 additions & 1 deletion yarn-project/circuits.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"dependencies": {
"@aztec/foundation": "workspace:^",
"@msgpack/msgpack": "^3.0.0-beta2",
"@noble/curves": "^1.0.0",
"@types/lodash.camelcase": "^4.3.7",
"@types/lodash.times": "^4.3.7",
"cross-fetch": "^3.1.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('ecdsa', () => {
ecdsa = new Ecdsa(wasm);
});

it.skip('should verify signature', () => {
it('should verify signature', () => {
// prettier-ignore
const privateKey = Buffer.from([
0x0b, 0x9b, 0x3a, 0xde, 0xe6, 0xb3, 0xd8, 0x1b, 0x28, 0xa0, 0x88, 0x6b, 0x2a, 0x84, 0x15, 0xc7,
Expand All @@ -24,7 +24,7 @@ describe('ecdsa', () => {
expect(verified).toBe(true);
});

it.skip('should recover public key from signature', () => {
it('should recover public key from signature', () => {
// prettier-ignore
const privateKey = Buffer.from([
0x0b, 0x9b, 0x3a, 0xde, 0xe6, 0xb3, 0xd8, 0x1b, 0x28, 0xa0, 0x88, 0x6b, 0x2a, 0x84, 0x15, 0xc7,
Expand Down
19 changes: 4 additions & 15 deletions yarn-project/circuits.js/src/barretenberg/crypto/ecdsa/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { IWasmModule } from '@aztec/foundation/wasm';
import { EcdsaSignature } from './signature.js';
import { CircuitsWasm } from '../../../index.js';
import { Signer } from '../index.js';
import { secp256k1 } from '@noble/curves/secp256k1';
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
import { numToUInt32BE } from '@aztec/foundation/serialize';
import { EcdsaSignature } from './signature.js';

export * from './signature.js';

Expand Down Expand Up @@ -45,18 +42,10 @@ export class Ecdsa implements Signer {
this.wasm.writeMemory(mem, msg);
this.wasm.call('ecdsa__construct_signature', mem, msg.length, 0, 32, 64, 96);

// TODO(#913): Understand why this doesn't work
// const sig = new EcdsaSignature(
// Buffer.from(this.wasm.getMemorySlice(32, 64)),
// Buffer.from(this.wasm.getMemorySlice(64, 96)),
// Buffer.from(this.wasm.getMemorySlice(96, 97)),
// );

const signature = secp256k1.sign(msg, privateKey);
return new EcdsaSignature(
toBufferBE(signature.r, 32),
toBufferBE(signature.s, 32),
numToUInt32BE(signature.recovery!).subarray(3, 4),
Buffer.from(this.wasm.getMemorySlice(32, 64)),
Buffer.from(this.wasm.getMemorySlice(64, 96)),
Buffer.from(this.wasm.getMemorySlice(96, 97)),
);
}

Expand Down
1 change: 0 additions & 1 deletion yarn-project/end-to-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"@aztec/sequencer-client": "workspace:^",
"@aztec/world-state": "workspace:^",
"@jest/globals": "^29.5.0",
"@noble/curves": "^1.0.0",
"@types/jest": "^29.5.0",
"@types/levelup": "^5.1.2",
"@types/lodash.every": "^4.6.7",
Expand Down
4 changes: 1 addition & 3 deletions yarn-project/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ __metadata:
"@aztec/yarn-project-base": "workspace:^"
"@jest/globals": ^29.5.0
"@msgpack/msgpack": ^3.0.0-beta2
"@noble/curves": ^1.0.0
"@types/detect-node": ^2.0.0
"@types/jest": ^29.5.0
"@types/lodash.camelcase": ^4.3.7
Expand Down Expand Up @@ -309,7 +308,6 @@ __metadata:
"@aztec/sequencer-client": "workspace:^"
"@aztec/world-state": "workspace:^"
"@jest/globals": ^29.5.0
"@noble/curves": ^1.0.0
"@rushstack/eslint-patch": ^1.1.4
"@types/jest": ^29.5.0
"@types/levelup": ^5.1.2
Expand Down Expand Up @@ -2380,7 +2378,7 @@ __metadata:
languageName: node
linkType: hard

"@noble/curves@npm:1.0.0, @noble/curves@npm:^1.0.0, @noble/curves@npm:~1.0.0":
"@noble/curves@npm:1.0.0, @noble/curves@npm:~1.0.0":
version: 1.0.0
resolution: "@noble/curves@npm:1.0.0"
dependencies:
Expand Down

0 comments on commit 570518d

Please sign in to comment.