From 6f446bf746cbb4c536203100c26c2167c6f4af0f Mon Sep 17 00:00:00 2001 From: Kyle Peacock Date: Wed, 8 Nov 2023 12:43:50 -0800 Subject: [PATCH] bls verification working --- README.md | 2 ++ package-lock.json | 11 ++++++----- packages/bls-verify/package.json | 3 ++- packages/bls-verify/src/index.test.ts | 8 +++----- packages/bls-verify/src/index.ts | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5b4bb747d..d6e554c66 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Use an Agent to interact with the Internet Computer from your JavaScript program This source code repository contains multiple npm packages, each under `./packages/`. +Note: the `@noble/curves` `verifyShortSignature` function has been audited and merged, but has not yet been released. Once the release is available, we will update the `@dfinity/agent` dependency to use it instead of this manually compiled version + ## Development ### Getting Started diff --git a/package-lock.json b/package-lock.json index 9b462e04c..08fe65ba0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1677,6 +1677,8 @@ }, "node_modules/@noble/curves": { "version": "1.2.0", + "resolved": "file:packages/bls-verify/noble-curves-1.2.0.tgz", + "integrity": "sha512-Ow/xR1GC0+Qwlos9GA4ueaG7fT48u04ifqmobWr9wtmA+uwWsYcoRToJosUTf2OBqdjVCdc8ZAHjjsNAzYvCCw==", "license": "MIT", "dependencies": { "@noble/hashes": "1.3.2" @@ -15143,6 +15145,7 @@ "node_modules/pkcs11js": { "version": "1.3.0", "dev": true, + "hasInstallScript": true, "license": "MIT", "dependencies": { "nan": "^2.15.0" @@ -20459,7 +20462,7 @@ "version": "0.19.3", "license": "Apache-2.0", "dependencies": { - "amcl-js": "file:src/vendor/amcl-js" + "@noble/curves": "file:noble-curves-1.2.0.tgz" }, "devDependencies": { "esbuild": "^0.15.16", @@ -20467,11 +20470,9 @@ "vitest": "^0.34.6" } }, - "packages/bls-verify/node_modules/amcl-js": { - "resolved": "packages/bls-verify/src/vendor/amcl-js", - "link": true + "packages/bls-verify/src/vendor/amcl-js": { + "extraneous": true }, - "packages/bls-verify/src/vendor/amcl-js": {}, "packages/candid": { "name": "@dfinity/candid", "version": "0.19.3", diff --git a/packages/bls-verify/package.json b/packages/bls-verify/package.json index 857282163..4dfc177ed 100644 --- a/packages/bls-verify/package.json +++ b/packages/bls-verify/package.json @@ -39,6 +39,7 @@ "build": "tsc -b && tsc -p tsconfig-cjs.json", "bundle": "esbuild --bundle src/index.ts --outfile=dist/index.js --platform=node", "size-limit": "size-limit", + "test": "vitest", "ci": "npm run prettier && npm run lint && npm run test", "lint": "eslint 'src' --ext '.js,.jsx,.ts,.tsx'", "lint:fix": "npm run lint -- --fix", @@ -47,7 +48,7 @@ "prettier:write": "npm run prettier -- --write" }, "dependencies": { - "amcl-js": "file:src/vendor/amcl-js" + "@noble/curves": "file:noble-curves-1.2.0.tgz" }, "devDependencies": { "esbuild": "^0.15.16", diff --git a/packages/bls-verify/src/index.test.ts b/packages/bls-verify/src/index.test.ts index fa835156f..a37d87446 100644 --- a/packages/bls-verify/src/index.test.ts +++ b/packages/bls-verify/src/index.test.ts @@ -3,6 +3,7 @@ import * as Cert from '../../agent/src/certificate'; import * as cbor from '../../agent/src/cbor'; import { fromHex } from '../../agent/src/utils/buffer'; import { Principal } from '@dfinity/principal'; +import { test, expect, vi } from 'vitest'; // Root public key for the IC main net, encoded as hex const IC_ROOT_KEY = @@ -16,9 +17,6 @@ const IC_ROOT_KEY = const SAMPLE_CERT = 'd9d9f7a364747265658301830182045820250f5e26868d9c1ea7ab29cbe9c15bf1c47c0d7605e803e39e375a7fe09c6ebb830183024e726571756573745f7374617475738301820458204b268227774ec77ff2b37ecb12157329d54cf376694bdd59ded7803efd82386f83025820edad510eaaa08ed2acd4781324e6446269da6753ec17760f206bbe81c465ff528301830183024b72656a6563745f636f64658203410383024e72656a6563745f6d6573736167658203584443616e69737465722069766733372d71696161612d61616161622d61616167612d63616920686173206e6f20757064617465206d6574686f64202772656769737465722783024673746174757382034872656a65637465648204582097232f31f6ab7ca4fe53eb6568fc3e02bc22fe94ab31d010e5fb3c642301f1608301820458203a48d1fc213d49307103104f7d72c2b5930edba8787b90631f343b3aa68a5f0a83024474696d65820349e2dc939091c696eb16697369676e6174757265583089a2be21b5fa8ac9fab1527e041327ce899d7da971436a1f2165393947b4d942365bfe5488710e61a619ba48388a21b16a64656c65676174696f6ea2697375626e65745f6964581dd77b2a2f7199b9a8aec93fe6fb588661358cf12223e9a3af7b4ebac4026b6365727469666963617465590231d9d9f7a26474726565830182045820ae023f28c3b9d966c8fb09f9ed755c828aadb5152e00aaf700b18c9c067294b483018302467375626e6574830182045820e83bb025f6574c8f31233dc0fe289ff546dfa1e49bd6116dd6e8896d90a4946e830182045820e782619092d69d5bebf0924138bd4116b0156b5a95e25c358ea8cf7e7161a661830183018204582062513fa926c9a9ef803ac284d620f303189588e1d3904349ab63b6470856fc4883018204582060e9a344ced2c9c4a96a0197fd585f2d259dbd193e4eada56239cac26087f9c58302581dd77b2a2f7199b9a8aec93fe6fb588661358cf12223e9a3af7b4ebac402830183024f63616e69737465725f72616e6765738203581bd9d9f781824a000000000020000001014a00000000002fffff010183024a7075626c69635f6b657982035885308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c050302010361009933e1f89e8a3c4d7fdcccdbd518089e2bd4d8180a261f18d9c247a52768ebce98dc7328a39814a8f911086a1dd50cbe015e2a53b7bf78b55288893daa15c346640e8831d72a12bdedd979d28470c34823b8d1c3f4795d9c3984a247132e94fe82045820996f17bb926be3315745dea7282005a793b58e76afeb5d43d1a28ce29d2d158583024474696d6582034995b8aac0e4eda2ea16697369676e61747572655830ace9fcdd9bc977e05d6328f889dc4e7c99114c737a494653cb27a1f55c06f4555e0f160980af5ead098acc195010b2f7'; -beforeEach(() => { - jest.setTimeout(10_000); -}); test('delegation works for canisters within the subnet range', async () => { // The certificate specifies the range from // 0x00000000002000000101 @@ -27,9 +25,9 @@ test('delegation works for canisters within the subnet range', async () => { const rangeStart = Principal.fromHex('00000000002000000101'); const rangeInterior = Principal.fromHex('000000000020000C0101'); const rangeEnd = Principal.fromHex('00000000002FFFFF0101'); - jest.useFakeTimers(); + vi.useFakeTimers(); async function verifies(canisterId) { - jest.setSystemTime(new Date(Date.parse('2022-02-23T07:38:00.652Z'))); + vi.setSystemTime(new Date(Date.parse('2022-02-23T07:38:00.652Z'))); await expect( Cert.Certificate.create({ certificate: fromHex(SAMPLE_CERT), diff --git a/packages/bls-verify/src/index.ts b/packages/bls-verify/src/index.ts index 189f8fcb6..c69a22777 100644 --- a/packages/bls-verify/src/index.ts +++ b/packages/bls-verify/src/index.ts @@ -9,5 +9,5 @@ export const blsVerify = async ( const pk = typeof primaryKey === 'string' ? primaryKey : toHex(primaryKey); const sig = typeof signature === 'string' ? signature : toHex(signature); const msg = typeof message === 'string' ? message : toHex(message); - return bls.verify(sig, msg, pk); + return bls.verifyShortSignature(sig, msg, pk); };