diff --git a/packages/agent/src/app-data-store.ts b/packages/agent/src/app-data-store.ts index dca19c401..54e72928e 100644 --- a/packages/agent/src/app-data-store.ts +++ b/packages/agent/src/app-data-store.ts @@ -6,10 +6,9 @@ import { DidKeyMethod } from '@web5/dids'; import { hkdf } from '@noble/hashes/hkdf'; import { sha256 } from '@noble/hashes/sha256'; import { sha512 } from '@noble/hashes/sha512'; -import { randomBytes } from '@web5/crypto/utils'; import { pbkdf2Async } from '@noble/hashes/pbkdf2'; import { Convert, MemoryStore } from '@web5/common'; -import { CryptoKey, Jose, XChaCha20Poly1305 } from '@web5/crypto'; +import { CryptoKey, Jose, utils as cryptoUtils, XChaCha20Poly1305 } from '@web5/crypto'; export type AppDataBackup = { /** @@ -295,7 +294,7 @@ export class AppDataVault implements AppDataStore { /** 6. Encrypt the Identity Agent's private key with the derived VUK * using XChaCha20-Poly1305 */ - const nonce = randomBytes(24); + const nonce = cryptoUtils.randomBytes(24); const privateKey = keyPair.privateKey.material; const { ciphertext: privateKeyCiphertext, diff --git a/packages/agent/src/dwn-manager.ts b/packages/agent/src/dwn-manager.ts index d610cd84c..531a210d2 100644 --- a/packages/agent/src/dwn-manager.ts +++ b/packages/agent/src/dwn-manager.ts @@ -9,10 +9,10 @@ import { } from '@tbd54566975/dwn-sdk-js'; import { Jose } from '@web5/crypto'; +import { Convert } from '@web5/common'; import { DidResolver } from '@web5/dids'; import { Readable } from 'readable-stream'; -import * as didUtils from '@web5/dids/utils'; -import { Convert } from '@web5/common'; +import { utils as didUtils } from '@web5/dids'; import { Cid, diff --git a/packages/agent/src/kms-local.ts b/packages/agent/src/kms-local.ts index b4bb334a3..a0e624131 100644 --- a/packages/agent/src/kms-local.ts +++ b/packages/agent/src/kms-local.ts @@ -1,7 +1,7 @@ import type { Web5Crypto } from '@web5/crypto'; import type { RequireOnly } from '@web5/common'; -import { isCryptoKeyPair, checkRequiredProperty } from '@web5/crypto/utils'; +import { utils as cryptoUtils } from '@web5/crypto'; import { EcdhAlgorithm, EcdsaAlgorithm, @@ -196,7 +196,7 @@ export class LocalKms implements KeyManagementSystem { // Create a ManagedKey or ManagedKeyPair using the generated key and store the private key material. let managedKeyOrKeyPair: GenerateKeyType; - if (isCryptoKeyPair(cryptoKey)) { + if (cryptoUtils.isCryptoKeyPair(cryptoKey)) { const privateKeyType = cryptoKey.privateKey.type as Web5Crypto.PrivateKeyType; const id = await this._privateKeyStore.importKey({ key : { material: cryptoKey.privateKey.material, type: privateKeyType}, @@ -360,7 +360,7 @@ export class LocalKms implements KeyManagementSystem { } private getAlgorithm(algorithmIdentifier: Web5Crypto.AlgorithmIdentifier): CryptoAlgorithm { - checkRequiredProperty({ property: 'name', inObject: algorithmIdentifier }); + cryptoUtils.checkRequiredProperty({ property: 'name', inObject: algorithmIdentifier }); const algorithm = this._supportedAlgorithms.get(algorithmIdentifier.name.toUpperCase()); if (algorithm === undefined) { diff --git a/packages/agent/src/rpc-client.ts b/packages/agent/src/rpc-client.ts index 9efc2861b..3af9fdadb 100644 --- a/packages/agent/src/rpc-client.ts +++ b/packages/agent/src/rpc-client.ts @@ -1,8 +1,8 @@ +import { utils as cryptoUtils } from '@web5/crypto'; + import type { JsonRpcResponse } from './json-rpc.js'; import type { DwnRpc, DwnRpcRequest, DwnRpcResponse } from './types/agent.js'; -import { randomUuid } from '@web5/crypto/utils'; - import { createJsonRpcRequest, parseJson } from './json-rpc.js'; /** @@ -54,7 +54,7 @@ class HttpDwnRpcClient implements DwnRpc { get transportProtocols() { return ['http:', 'https:']; } async sendDwnRequest(request: DwnRpcRequest): Promise { - const requestId = randomUuid(); + const requestId = cryptoUtils.randomUuid(); const jsonRpcRequest = createJsonRpcRequest(requestId, 'dwn.processMessage', { target : request.targetDid, message : request.message diff --git a/packages/agent/src/store-managed-key.ts b/packages/agent/src/store-managed-key.ts index 696e7bb7c..41a35b596 100644 --- a/packages/agent/src/store-managed-key.ts +++ b/packages/agent/src/store-managed-key.ts @@ -1,13 +1,17 @@ import type { RecordsWriteMessage, RecordsWriteOptions } from '@tbd54566975/dwn-sdk-js'; -import { randomUuid } from '@web5/crypto/utils'; +import { utils as cryptoUtils } from '@web5/crypto'; import { Convert, removeEmptyObjects, removeUndefinedProperties } from '@web5/common'; -import type { ManagedKeyPair, ManagedKeyStore, ManagedPrivateKey } from './types/managed-key.js'; +import type { DwnResponse, Web5ManagedAgent } from './types/agent.js'; +import type { + ManagedKey, + ManagedKeyPair, + ManagedKeyStore, + ManagedPrivateKey +} from './types/managed-key.js'; -import { DwnResponse, Web5ManagedAgent } from './types/agent.js'; import { isManagedKeyPair } from './utils.js'; -import { ManagedKey } from './types/managed-key.js'; type EncodedPrivateKey = Omit & { // Key material, encoded as Base64Url. @@ -152,7 +156,7 @@ export class KeyStoreDwn implements ManagedKeyStore