Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from bloock/feature/EIT-1898
Browse files Browse the repository at this point in the history
EIT-1898 | Implement Sign function in JS SDK
  • Loading branch information
marcbaque authored Mar 7, 2022
2 parents 58cb3c0 + 458ecd2 commit eaca777
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 21 deletions.
49 changes: 39 additions & 10 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bloock/sdk",
"version": "1.3.3",
"version": "1.4.0",
"description": "",
"keywords": [],
"main": "dist/lib/index.js",
Expand All @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions src/record/entity/record.entity.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -92,4 +93,16 @@ export class Record {
public getUint8ArrayHash(): Uint8Array {
return Utils.hexToBytes(this.hash)
}

public sign(privateKey: string): Record {
const privKey = Buffer.from(privateKey, 'hex')

if (!secp256k1.privateKeyVerify(privKey)) {
throw "Sign: Invalid private key provided"
}

const signObj = secp256k1.ecdsaSign(this.getUint8ArrayHash(), privKey)

return new Record(this.hash)
}
}
12 changes: 2 additions & 10 deletions test/acceptance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -188,7 +180,7 @@ describe('Acceptance Tests', () => {

await expect(sdk.getProof(records)).rejects.toEqual(
new HttpRequestException(
"Message '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' not found."
"Record '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' not found."
)
)
})
Expand Down Expand Up @@ -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."
)
)
})
Expand Down

0 comments on commit eaca777

Please sign in to comment.