diff --git a/wrappers/javascript/aries-askar-nodejs/src/NodeJSAriesAskar.ts b/wrappers/javascript/aries-askar-nodejs/src/NodeJSAriesAskar.ts index 2dac942cf..9a961bdcc 100644 --- a/wrappers/javascript/aries-askar-nodejs/src/NodeJSAriesAskar.ts +++ b/wrappers/javascript/aries-askar-nodejs/src/NodeJSAriesAskar.ts @@ -136,6 +136,7 @@ function handleReturnPointer(returnValue: Buffer): Return { export class NodeJSAriesAskar implements AriesAskar { private promisify = async (method: (nativeCallbackPtr: Buffer, id: number) => void): Promise => { return new Promise((resolve, reject) => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const cb: NativeCallback = (id, _) => { deallocateCallbackBuffer(id) diff --git a/wrappers/javascript/aries-askar-nodejs/tests/migration.test.ts b/wrappers/javascript/aries-askar-nodejs/tests/migration.test.ts index c6dc4e534..8b3404d7e 100644 --- a/wrappers/javascript/aries-askar-nodejs/tests/migration.test.ts +++ b/wrappers/javascript/aries-askar-nodejs/tests/migration.test.ts @@ -1,4 +1,4 @@ -import { ariesAskar, Migration } from '@hyperledger/aries-askar-shared' +import { Migration } from '@hyperledger/aries-askar-shared' import fs from 'fs' import path from 'path' diff --git a/wrappers/javascript/aries-askar-nodejs/tests/store.test.ts b/wrappers/javascript/aries-askar-nodejs/tests/store.test.ts index c6b11dd23..d8bcbefeb 100644 --- a/wrappers/javascript/aries-askar-nodejs/tests/store.test.ts +++ b/wrappers/javascript/aries-askar-nodejs/tests/store.test.ts @@ -1,4 +1,4 @@ -import { Store, StoreKeyMethod, Key, KeyAlgs, AriesAskarError } from '@hyperledger/aries-askar-shared' +import { Store, StoreKeyMethod, Key, KeyAlgs, AriesAskarError, KdfMethod } from '@hyperledger/aries-askar-shared' import { promises } from 'fs' import { firstEntry, getRawKey, secondEntry, setupWallet, testStoreUri } from './utils' @@ -18,6 +18,34 @@ describe('Store and Session', () => { await store.close(true) }) + test('argon2i mod', async () => { + const argon2iModStore = await Store.provision({ + recreate: true, + passKey: 'abc', + uri: testStoreUri, + keyMethod: new StoreKeyMethod(KdfMethod.Argon2IMod), + }) + + const session = await argon2iModStore.openSession() + await expect(session.fetch({ name: 'unknownKey', category: 'unknownCategory' })).resolves.toBeNull() + + await argon2iModStore.close() + }) + + test('argon2i int', async () => { + const argon2iIntStore = await Store.provision({ + recreate: true, + passKey: 'abc', + uri: testStoreUri, + keyMethod: new StoreKeyMethod(KdfMethod.Argon2IInt), + }) + + const session = await argon2iIntStore.openSession() + await expect(session.fetch({ name: 'unknownKey', category: 'unknownCategory' })).resolves.toBeNull() + + await argon2iIntStore.close() + }) + test('Rekey', async () => { const initialKey = Store.generateRawKey() @@ -33,12 +61,12 @@ describe('Store and Session', () => { recreate: true, profile: 'rekey', uri: `sqlite://${storagePath}/rekey.db`, - keyMethod: StoreKeyMethod.Raw, + keyMethod: new StoreKeyMethod(KdfMethod.Raw), passKey: initialKey, }) const newKey = Store.generateRawKey() - await newStore.rekey({ keyMethod: StoreKeyMethod.Raw, passKey: newKey }) + await newStore.rekey({ keyMethod: new StoreKeyMethod(KdfMethod.Raw), passKey: newKey }) await newStore.close() @@ -46,7 +74,7 @@ describe('Store and Session', () => { Store.open({ profile: 'rekey', uri: `sqlite://${storagePath}/rekey.db`, - keyMethod: StoreKeyMethod.Raw, + keyMethod: new StoreKeyMethod(KdfMethod.Raw), passKey: initialKey, }) ).rejects.toThrowError(AriesAskarError) @@ -54,7 +82,7 @@ describe('Store and Session', () => { newStore = await Store.open({ profile: 'rekey', uri: `sqlite://${storagePath}/rekey.db`, - keyMethod: StoreKeyMethod.Raw, + keyMethod: new StoreKeyMethod(KdfMethod.Raw), passKey: newKey, }) @@ -215,7 +243,7 @@ describe('Store and Session', () => { if (!store.uri.includes(':memory:')) { // Test accessing profile after re-opening const key = getRawKey() - const store2 = await Store.open({ uri: testStoreUri, keyMethod: StoreKeyMethod.Raw, passKey: key }) + const store2 = await Store.open({ uri: testStoreUri, keyMethod: new StoreKeyMethod(KdfMethod.Raw), passKey: key }) const session3 = await store2.openSession() //Should not find previously stored record await expect(session3.count(firstEntry)).resolves.toStrictEqual(0) diff --git a/wrappers/javascript/aries-askar-nodejs/tests/utils/initialize.ts b/wrappers/javascript/aries-askar-nodejs/tests/utils/initialize.ts index baf63d4a6..fb7831272 100644 --- a/wrappers/javascript/aries-askar-nodejs/tests/utils/initialize.ts +++ b/wrappers/javascript/aries-askar-nodejs/tests/utils/initialize.ts @@ -1,5 +1,5 @@ import '@hyperledger/aries-askar-nodejs' -import { Store, StoreKeyMethod } from '@hyperledger/aries-askar-shared' +import { Store, StoreKeyMethod, KdfMethod } from '@hyperledger/aries-askar-shared' export const getRawKey = () => Store.generateRawKey(Buffer.from('00000000000000000000000000000My1')) export const testStoreUri = process.env.URI || 'sqlite://:memory:' @@ -10,7 +10,7 @@ export const setupWallet = async () => { return await Store.provision({ recreate: true, uri: testStoreUri, - keyMethod: StoreKeyMethod.Raw, + keyMethod: new StoreKeyMethod(KdfMethod.Raw), passKey: key, }) } diff --git a/wrappers/javascript/aries-askar-react-native/src/library/NativeBindings.ts b/wrappers/javascript/aries-askar-react-native/src/library/NativeBindings.ts index d3c51a347..f0f6ebc8c 100644 --- a/wrappers/javascript/aries-askar-react-native/src/library/NativeBindings.ts +++ b/wrappers/javascript/aries-askar-react-native/src/library/NativeBindings.ts @@ -2,7 +2,7 @@ import type { CallbackWithResponse, ReturnObject } from '../utils' type LocalKeyHandle = string -// TODO: convert all any types +// TODO: convert all unknown types export interface NativeBindings { version(options: Record): string getCurrentError(options: Record): string @@ -37,117 +37,117 @@ export interface NativeBindings { keyAeadGetParams(options: { localKeyHandle: string }): ReturnObject<{ nonceLength: number; tagLength: number }> - keyAeadRandomNonce(options: any): ReturnObject + keyAeadRandomNonce(options: unknown): ReturnObject - keyConvert(options: any): ReturnObject + keyConvert(options: unknown): ReturnObject - keyCryptoBox(options: any): ReturnObject + keyCryptoBox(options: unknown): ReturnObject - keyCryptoBoxOpen(options: any): ReturnObject + keyCryptoBoxOpen(options: unknown): ReturnObject keyCryptoBoxRandomNonce(options: Record): ReturnObject - keyCryptoBoxSeal(options: any): ReturnObject + keyCryptoBoxSeal(options: unknown): ReturnObject - keyCryptoBoxSealOpen(options: any): ReturnObject + keyCryptoBoxSealOpen(options: unknown): ReturnObject - keyDeriveEcdh1pu(options: any): ReturnObject + keyDeriveEcdh1pu(options: unknown): ReturnObject - keyDeriveEcdhEs(options: any): ReturnObject + keyDeriveEcdhEs(options: unknown): ReturnObject - keyEntryListCount(options: any): ReturnObject + keyEntryListCount(options: unknown): ReturnObject - keyEntryListFree(options: any): ReturnObject + keyEntryListFree(options: unknown): ReturnObject - keyEntryListGetAlgorithm(options: any): ReturnObject + keyEntryListGetAlgorithm(options: unknown): ReturnObject - keyEntryListGetMetadata(options: any): ReturnObject + keyEntryListGetMetadata(options: unknown): ReturnObject - keyEntryListGetName(options: any): ReturnObject + keyEntryListGetName(options: unknown): ReturnObject - keyEntryListGetTags(options: any): ReturnObject + keyEntryListGetTags(options: unknown): ReturnObject - keyEntryListLoadLocal(options: any): ReturnObject + keyEntryListLoadLocal(options: unknown): ReturnObject - keyFree(options: any): ReturnObject + keyFree(options: unknown): ReturnObject - keyFromJwk(options: any): ReturnObject + keyFromJwk(options: unknown): ReturnObject - keyFromKeyExchange(options: any): ReturnObject + keyFromKeyExchange(options: unknown): ReturnObject - keyFromPublicBytes(options: any): ReturnObject + keyFromPublicBytes(options: unknown): ReturnObject - keyFromSecretBytes(options: any): ReturnObject + keyFromSecretBytes(options: unknown): ReturnObject - keyFromSeed(options: any): ReturnObject + keyFromSeed(options: unknown): ReturnObject - keyGenerate(options: any): ReturnObject + keyGenerate(options: unknown): ReturnObject - keyGetAlgorithm(options: any): ReturnObject + keyGetAlgorithm(options: unknown): ReturnObject - keyGetEphemeral(options: any): ReturnObject + keyGetEphemeral(options: unknown): ReturnObject - keyGetJwkPublic(options: any): ReturnObject + keyGetJwkPublic(options: unknown): ReturnObject - keyGetJwkSecret(options: any): ReturnObject + keyGetJwkSecret(options: unknown): ReturnObject - keyGetJwkThumbprint(options: any): ReturnObject + keyGetJwkThumbprint(options: unknown): ReturnObject - keyGetPublicBytes(options: any): ReturnObject + keyGetPublicBytes(options: unknown): ReturnObject - keyGetSecretBytes(options: any): ReturnObject + keyGetSecretBytes(options: unknown): ReturnObject - keySignMessage(options: any): ReturnObject + keySignMessage(options: unknown): ReturnObject - keyUnwrapKey(options: any): ReturnObject + keyUnwrapKey(options: unknown): ReturnObject - keyVerifySignature(options: any): ReturnObject + keyVerifySignature(options: unknown): ReturnObject - keyWrapKey(options: any): ReturnObject<{ buffer: ArrayBuffer; tagPos: number; noncePos: number }> + keyWrapKey(options: unknown): ReturnObject<{ buffer: ArrayBuffer; tagPos: number; noncePos: number }> - scanFree(options: any): ReturnObject + scanFree(options: unknown): ReturnObject - scanNext(options: any): ReturnObject + scanNext(options: unknown): ReturnObject - scanStart(options: any): ReturnObject + scanStart(options: unknown): ReturnObject - sessionClose(options: any): ReturnObject + sessionClose(options: unknown): ReturnObject - sessionCount(options: any): ReturnObject + sessionCount(options: unknown): ReturnObject - sessionFetch(options: any): ReturnObject + sessionFetch(options: unknown): ReturnObject - sessionFetchAll(options: any): ReturnObject + sessionFetchAll(options: unknown): ReturnObject - sessionFetchAllKeys(options: any): ReturnObject + sessionFetchAllKeys(options: unknown): ReturnObject - sessionFetchKey(options: any): ReturnObject + sessionFetchKey(options: unknown): ReturnObject - sessionInsertKey(options: any): ReturnObject + sessionInsertKey(options: unknown): ReturnObject - sessionRemoveAll(options: any): ReturnObject + sessionRemoveAll(options: unknown): ReturnObject - sessionRemoveKey(options: any): ReturnObject + sessionRemoveKey(options: unknown): ReturnObject - sessionStart(options: any): ReturnObject + sessionStart(options: unknown): ReturnObject - sessionUpdate(options: any): ReturnObject + sessionUpdate(options: unknown): ReturnObject - sessionUpdateKey(options: any): ReturnObject + sessionUpdateKey(options: unknown): ReturnObject - setCustomLogger(options: any): ReturnObject + setCustomLogger(options: unknown): ReturnObject - setDefaultLogger(options: any): ReturnObject + setDefaultLogger(options: unknown): ReturnObject - setMaxLogLevel(options: any): ReturnObject + setMaxLogLevel(options: unknown): ReturnObject - storeClose(options: any): ReturnObject + storeClose(options: unknown): ReturnObject - storeCreateProfile(options: any): ReturnObject + storeCreateProfile(options: unknown): ReturnObject storeGenerateRawKey(options: { seed?: ArrayBuffer }): ReturnObject - storeGetProfileName(options: any): ReturnObject + storeGetProfileName(options: unknown): ReturnObject storeOpen(options: { specUri: string @@ -157,13 +157,13 @@ export interface NativeBindings { cb: CallbackWithResponse }): ReturnObject - storeProvision(options: any): ReturnObject + storeProvision(options: unknown): ReturnObject - storeRekey(options: any): ReturnObject + storeRekey(options: unknown): ReturnObject - storeRemove(options: any): ReturnObject + storeRemove(options: unknown): ReturnObject - storeRemoveProfile(options: any): ReturnObject + storeRemoveProfile(options: unknown): ReturnObject - migrateIndySdk(options: any): ReturnObject + migrateIndySdk(options: unknown): ReturnObject } diff --git a/wrappers/javascript/aries-askar-shared/src/ariesAskar/AriesAskar.ts b/wrappers/javascript/aries-askar-shared/src/ariesAskar/AriesAskar.ts index d2855dced..bec3c26ab 100644 --- a/wrappers/javascript/aries-askar-shared/src/ariesAskar/AriesAskar.ts +++ b/wrappers/javascript/aries-askar-shared/src/ariesAskar/AriesAskar.ts @@ -217,7 +217,7 @@ export type StoreProvisionOptions = { profile?: string recreate: boolean } -export type StoreRekeyOptions = { storeHandle: StoreHandle; keyMethod: string; passKey: string } +export type StoreRekeyOptions = { storeHandle: StoreHandle; keyMethod?: string; passKey: string } export type StoreRemoveOptions = { specUri: string } export type StoreRemoveProfileOptions = { storeHandle: StoreHandle; profile: string } diff --git a/wrappers/javascript/aries-askar-shared/src/enums/StoreKeyMethod.ts b/wrappers/javascript/aries-askar-shared/src/enums/StoreKeyMethod.ts deleted file mode 100644 index ba19870cf..000000000 --- a/wrappers/javascript/aries-askar-shared/src/enums/StoreKeyMethod.ts +++ /dev/null @@ -1,6 +0,0 @@ -export enum StoreKeyMethod { - Raw = 'raw', - // TODO: we might have to un-enum this as kdf needs additional params seperated by ':' - Kdf = 'kdf', - None = 'none', -} diff --git a/wrappers/javascript/aries-askar-shared/src/enums/index.ts b/wrappers/javascript/aries-askar-shared/src/enums/index.ts index 10a985bc7..04644176b 100644 --- a/wrappers/javascript/aries-askar-shared/src/enums/index.ts +++ b/wrappers/javascript/aries-askar-shared/src/enums/index.ts @@ -2,4 +2,3 @@ export * from './KeyAlgs' export * from './KeyMethod' export * from './SigAlgs' export * from './LogLevel' -export * from './StoreKeyMethod' diff --git a/wrappers/javascript/aries-askar-shared/src/store/Store.ts b/wrappers/javascript/aries-askar-shared/src/store/Store.ts index dcd2e560b..78ec8eb84 100644 --- a/wrappers/javascript/aries-askar-shared/src/store/Store.ts +++ b/wrappers/javascript/aries-askar-shared/src/store/Store.ts @@ -1,5 +1,5 @@ import type { StoreHandle } from '../crypto' -import type { StoreKeyMethod } from '../enums/StoreKeyMethod' +import type { StoreKeyMethod } from './StoreKeyMethod' import { ariesAskar } from '../ariesAskar' @@ -36,8 +36,8 @@ export class Store { return await ariesAskar.storeRemoveProfile({ profile: name, storeHandle: this.handle }) } - public async rekey({ keyMethod, passKey }: { keyMethod: StoreKeyMethod; passKey: string }) { - return await ariesAskar.storeRekey({ keyMethod, passKey, storeHandle: this.handle }) + public async rekey({ keyMethod, passKey }: { keyMethod?: StoreKeyMethod; passKey: string }) { + return await ariesAskar.storeRekey({ keyMethod: keyMethod?.toUri(), passKey, storeHandle: this.handle }) } public static async provision({ @@ -53,7 +53,13 @@ export class Store { profile?: string recreate: boolean }) { - const handle = await ariesAskar.storeProvision({ specUri: uri, keyMethod, profile, passKey, recreate }) + const handle = await ariesAskar.storeProvision({ + specUri: uri, + keyMethod: keyMethod?.toUri(), + profile, + passKey, + recreate, + }) return new Store({ handle, uri }) } @@ -68,7 +74,7 @@ export class Store { passKey?: string profile?: string }) { - const handle = await ariesAskar.storeOpen({ profile, passKey, keyMethod, specUri: uri }) + const handle = await ariesAskar.storeOpen({ profile, passKey, keyMethod: keyMethod?.toUri(), specUri: uri }) return new Store({ uri, handle }) } diff --git a/wrappers/javascript/aries-askar-shared/src/store/StoreKeyMethod.ts b/wrappers/javascript/aries-askar-shared/src/store/StoreKeyMethod.ts new file mode 100644 index 000000000..c8acf73ae --- /dev/null +++ b/wrappers/javascript/aries-askar-shared/src/store/StoreKeyMethod.ts @@ -0,0 +1,18 @@ +export enum KdfMethod { + Raw = 'raw', + None = 'none', + Argon2IMod = 'kdf:argon2i:mod', + Argon2IInt = 'kdf:argon2i:int', +} + +export class StoreKeyMethod { + private method: KdfMethod + + public constructor(method: KdfMethod) { + this.method = method + } + + public toUri() { + return this.method.toString() + } +} diff --git a/wrappers/javascript/aries-askar-shared/src/store/index.ts b/wrappers/javascript/aries-askar-shared/src/store/index.ts index 866c5b400..7a69f4d59 100644 --- a/wrappers/javascript/aries-askar-shared/src/store/index.ts +++ b/wrappers/javascript/aries-askar-shared/src/store/index.ts @@ -6,3 +6,4 @@ export * from './Scan' export * from './Store' export * from './OpenSession' export * from './Session' +export * from './StoreKeyMethod'