diff --git a/packages/askar/package.json b/packages/askar/package.json index 1f7935175a..af83ba53ea 100644 --- a/packages/askar/package.json +++ b/packages/askar/package.json @@ -26,12 +26,14 @@ "dependencies": { "@aries-framework/core": "0.3.3", "@hyperledger/aries-askar-shared": "^0.1.0-dev.1", + "bn.js": "^5.2.1", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", "rxjs": "^7.2.0", "tsyringe": "^4.7.0" }, "devDependencies": { + "@types/bn.js": "^5.1.0", "@hyperledger/aries-askar-nodejs": "^0.1.0-dev.1", "reflect-metadata": "^0.1.13", "rimraf": "^4.0.7", diff --git a/packages/askar/src/wallet/AskarWallet.ts b/packages/askar/src/wallet/AskarWallet.ts index 432e50cdda..c84370cadf 100644 --- a/packages/askar/src/wallet/AskarWallet.ts +++ b/packages/askar/src/wallet/AskarWallet.ts @@ -34,7 +34,6 @@ import { FileSystem, WalletNotFoundError, } from '@aries-framework/core' -// eslint-disable-next-line import/order import { StoreKeyMethod, KeyAlgs, @@ -43,6 +42,8 @@ import { Key as AskarKey, keyAlgFromString, } from '@hyperledger/aries-askar-shared' +// eslint-disable-next-line import/order +import BigNumber from 'bn.js' const isError = (error: unknown): error is Error => error instanceof Error @@ -669,7 +670,9 @@ export class AskarWallet implements Wallet { public async generateNonce(): Promise { try { - return TypedArrayEncoder.toUtf8String(CryptoBox.randomNonce()) + // generate an 80-bit nonce suitable for AnonCreds proofs + const nonce = CryptoBox.randomNonce().slice(0, 10) + return new BigNumber(nonce).toString() } catch (error) { if (!isError(error)) { throw new AriesFrameworkError('Attempted to throw error, but it was not of type Error', { cause: error }) diff --git a/packages/askar/src/wallet/__tests__/AskarWallet.test.ts b/packages/askar/src/wallet/__tests__/AskarWallet.test.ts index 15bbf174cd..94732a15b0 100644 --- a/packages/askar/src/wallet/__tests__/AskarWallet.test.ts +++ b/packages/askar/src/wallet/__tests__/AskarWallet.test.ts @@ -57,7 +57,9 @@ describe('AskarWallet basic operations', () => { }) test('Generate Nonce', async () => { - await expect(askarWallet.generateNonce()).resolves.toEqual(expect.any(String)) + const nonce = await askarWallet.generateNonce() + + expect(nonce).toMatch(/[0-9]+/) }) test('Create ed25519 keypair', async () => {