From 5157234c3245677fae4ded2c0f2001cf3849a0c8 Mon Sep 17 00:00:00 2001 From: edutomesco Date: Fri, 25 Feb 2022 09:25:29 +0100 Subject: [PATCH 1/6] EIT-1898 | add sign function --- package-lock.json | 49 ++++++++++++++++++++++++------ package.json | 1 + src/record/entity/record.entity.ts | 11 +++++++ 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 792b110..b5bb83a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@bloock/sdk", - "version": "1.2.0", + "version": "1.3.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@bloock/sdk", - "version": "1.2.0", + "version": "1.3.3", "license": "MIT", "dependencies": { "axios": "^0.21.1", @@ -14,6 +14,7 @@ "buffer": "^5.6.0", "json-stable-stringify": "^1.0.1", "reflect-metadata": "^0.1.13", + "secp256k1": "^4.0.3", "ts-polyfill": "^3.8.2", "tsyringe": "^4.4.0", "web3": "^1.3.0" @@ -9569,12 +9570,12 @@ "integrity": "sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA==" }, "node_modules/secp256k1": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-4.0.2.tgz", - "integrity": "sha512-UDar4sKvWAksIlfX3xIaQReADn+WFnHvbVujpcbr+9Sf/69odMwy2MUsz5CKLQgX9nsIyrjuxL2imVyoNHa3fg==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-4.0.3.tgz", + "integrity": "sha512-NLZVf+ROMxwtEj3Xa562qgv2BK5e2WNmXPiOdVIPLgs6lyTzMvBq0aWTYMI5XCP9jZMVKOcqZLw/Wc4vDkuxhA==", "hasInstallScript": true, "dependencies": { - "elliptic": "^6.5.2", + "elliptic": "^6.5.4", "node-addon-api": "^2.0.0", "node-gyp-build": "^4.2.0" }, @@ -9582,6 +9583,20 @@ "node": ">=10.0.0" } }, + "node_modules/secp256k1/node_modules/elliptic": { + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz", + "integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==", + "dependencies": { + "bn.js": "^4.11.9", + "brorand": "^1.1.0", + "hash.js": "^1.0.0", + "hmac-drbg": "^1.0.1", + "inherits": "^2.0.4", + "minimalistic-assert": "^1.0.1", + "minimalistic-crypto-utils": "^1.0.1" + } + }, "node_modules/secp256k1/node_modules/node-gyp-build": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz", @@ -19426,15 +19441,29 @@ "integrity": "sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA==" }, "secp256k1": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-4.0.2.tgz", - "integrity": "sha512-UDar4sKvWAksIlfX3xIaQReADn+WFnHvbVujpcbr+9Sf/69odMwy2MUsz5CKLQgX9nsIyrjuxL2imVyoNHa3fg==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-4.0.3.tgz", + "integrity": "sha512-NLZVf+ROMxwtEj3Xa562qgv2BK5e2WNmXPiOdVIPLgs6lyTzMvBq0aWTYMI5XCP9jZMVKOcqZLw/Wc4vDkuxhA==", "requires": { - "elliptic": "^6.5.2", + "elliptic": "^6.5.4", "node-addon-api": "^2.0.0", "node-gyp-build": "^4.2.0" }, "dependencies": { + "elliptic": { + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz", + "integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==", + "requires": { + "bn.js": "^4.11.9", + "brorand": "^1.1.0", + "hash.js": "^1.0.0", + "hmac-drbg": "^1.0.1", + "inherits": "^2.0.4", + "minimalistic-assert": "^1.0.1", + "minimalistic-crypto-utils": "^1.0.1" + } + }, "node-gyp-build": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz", diff --git a/package.json b/package.json index 45306e3..f72af42 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "buffer": "^5.6.0", "json-stable-stringify": "^1.0.1", "reflect-metadata": "^0.1.13", + "secp256k1": "^4.0.3", "ts-polyfill": "^3.8.2", "tsyringe": "^4.4.0", "web3": "^1.3.0" diff --git a/src/record/entity/record.entity.ts b/src/record/entity/record.entity.ts index d1f80f3..791c1f3 100644 --- a/src/record/entity/record.entity.ts +++ b/src/record/entity/record.entity.ts @@ -1,3 +1,4 @@ +import secp256k1 from 'secp256k1' import { HashingClient } from '../../infrastructure/hashing.client' import { Keccak } from '../../infrastructure/hashing/keccak' import { Utils } from '../../shared/utils' @@ -92,4 +93,14 @@ export class Record { public getUint8ArrayHash(): Uint8Array { return Utils.hexToBytes(this.hash) } + + public sign(privateKey: string) { + const privKey = Buffer.from(privateKey, 'hex') + + if (!secp256k1.privateKeyVerify(privKey)) { + throw "Sign: Invalid private key provided" + } + + const signObj = secp256k1.ecdsaSign(this.getUint8ArrayHash(), privKey) + } } From dffdfb073c61e310ca6905dccd0fb52d5fa3e9a5 Mon Sep 17 00:00:00 2001 From: edutomesco Date: Fri, 25 Feb 2022 12:36:22 +0100 Subject: [PATCH 2/6] EIT-1898 | test if test fail --- src/record/entity/record.entity.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/record/entity/record.entity.ts b/src/record/entity/record.entity.ts index 791c1f3..e75be93 100644 --- a/src/record/entity/record.entity.ts +++ b/src/record/entity/record.entity.ts @@ -1,4 +1,3 @@ -import secp256k1 from 'secp256k1' import { HashingClient } from '../../infrastructure/hashing.client' import { Keccak } from '../../infrastructure/hashing/keccak' import { Utils } from '../../shared/utils' @@ -94,13 +93,5 @@ export class Record { return Utils.hexToBytes(this.hash) } - public sign(privateKey: string) { - const privKey = Buffer.from(privateKey, 'hex') - if (!secp256k1.privateKeyVerify(privKey)) { - throw "Sign: Invalid private key provided" - } - - const signObj = secp256k1.ecdsaSign(this.getUint8ArrayHash(), privKey) - } } From b2eb59069861bca293e94a30827362cf1066c2bd Mon Sep 17 00:00:00 2001 From: edutomesco Date: Fri, 25 Feb 2022 12:39:46 +0100 Subject: [PATCH 3/6] EIT-1898 | add sign function again --- src/record/entity/record.entity.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/record/entity/record.entity.ts b/src/record/entity/record.entity.ts index e75be93..791c1f3 100644 --- a/src/record/entity/record.entity.ts +++ b/src/record/entity/record.entity.ts @@ -1,3 +1,4 @@ +import secp256k1 from 'secp256k1' import { HashingClient } from '../../infrastructure/hashing.client' import { Keccak } from '../../infrastructure/hashing/keccak' import { Utils } from '../../shared/utils' @@ -93,5 +94,13 @@ export class Record { return Utils.hexToBytes(this.hash) } + public sign(privateKey: string) { + const privKey = Buffer.from(privateKey, 'hex') + if (!secp256k1.privateKeyVerify(privKey)) { + throw "Sign: Invalid private key provided" + } + + const signObj = secp256k1.ecdsaSign(this.getUint8ArrayHash(), privKey) + } } From 5f450c292822bd02824b323523e73c0a897b899a Mon Sep 17 00:00:00 2001 From: edutomesco Date: Mon, 28 Feb 2022 10:05:22 +0100 Subject: [PATCH 4/6] EIT-1898 | add Record return to signing function --- src/record/entity/record.entity.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/record/entity/record.entity.ts b/src/record/entity/record.entity.ts index 791c1f3..1df0987 100644 --- a/src/record/entity/record.entity.ts +++ b/src/record/entity/record.entity.ts @@ -94,7 +94,7 @@ export class Record { return Utils.hexToBytes(this.hash) } - public sign(privateKey: string) { + public sign(privateKey: string): Record { const privKey = Buffer.from(privateKey, 'hex') if (!secp256k1.privateKeyVerify(privKey)) { @@ -102,5 +102,7 @@ export class Record { } const signObj = secp256k1.ecdsaSign(this.getUint8ArrayHash(), privKey) + + return new Record(this.hash) } } From 2c753171eb0b30e8b00dae96f3db9cdb13b09085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Baque=CC=81?= Date: Mon, 7 Mar 2022 16:34:06 +0100 Subject: [PATCH 5/6] Fix acceptance tests --- test/acceptance.test.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/test/acceptance.test.ts b/test/acceptance.test.ts index c19efd0..7b66e7c 100644 --- a/test/acceptance.test.ts +++ b/test/acceptance.test.ts @@ -117,14 +117,6 @@ describe('Acceptance Tests', () => { await expect(sdk.getRecords(records)).rejects.toEqual(new InvalidRecordException()) }) - test('test_get_anchor_non_existing_anchor', async () => { - const sdk = getSdk() - - await expect(sdk.getAnchor(666666666666666666)).rejects.toEqual( - new HttpRequestException('Anchor not found') - ) - }) - test('test_get_anchor_invalid_input', async () => { const sdk = getSdk() @@ -188,7 +180,7 @@ describe('Acceptance Tests', () => { await expect(sdk.getProof(records)).rejects.toEqual( new HttpRequestException( - "Message '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' not found." + "Record '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' not found." ) ) }) @@ -248,7 +240,7 @@ describe('Acceptance Tests', () => { await expect(sdk.verifyRecords(records, Network.BLOOCK_CHAIN)).rejects.toEqual( new HttpRequestException( - "Message '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' not found." + "Record '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' not found." ) ) }) From 458ecd2b23c022b74826706e2cbe3c863fd655d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Baque=CC=81?= Date: Mon, 7 Mar 2022 16:36:07 +0100 Subject: [PATCH 6/6] Bump version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f72af42..89a5a8a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bloock/sdk", - "version": "1.3.3", + "version": "1.4.0", "description": "", "keywords": [], "main": "dist/lib/index.js",