Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of named exports until React Native supports #257

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/agent/src/app-data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
/**
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/agent/src/dwn-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions packages/agent/src/kms-local.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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<T>;
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},
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions packages/agent/src/rpc-client.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down Expand Up @@ -54,7 +54,7 @@ class HttpDwnRpcClient implements DwnRpc {
get transportProtocols() { return ['http:', 'https:']; }

async sendDwnRequest(request: DwnRpcRequest): Promise<DwnRpcResponse> {
const requestId = randomUuid();
const requestId = cryptoUtils.randomUuid();
const jsonRpcRequest = createJsonRpcRequest(requestId, 'dwn.processMessage', {
target : request.targetDid,
message : request.message
Expand Down
20 changes: 12 additions & 8 deletions packages/agent/src/store-managed-key.ts
Original file line number Diff line number Diff line change
@@ -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<ManagedPrivateKey, 'material'> & {
// Key material, encoded as Base64Url.
Expand Down Expand Up @@ -152,7 +156,7 @@ export class KeyStoreDwn implements ManagedKeyStore<string, ManagedKey | Managed
} else {
// If an ID wasn't specified, generate one.
if (!key.id) {
key.id = randomUuid();
key.id = cryptoUtils.randomUuid();
}
keyId = key.id;
}
Expand Down Expand Up @@ -430,7 +434,7 @@ export class KeyStoreMemory implements ManagedKeyStore<string, ManagedKey | Mana
} else {
// If an ID wasn't specified, generate one.
if (!key.id) {
key.id = randomUuid();
key.id = cryptoUtils.randomUuid();
}
id = key.id;
}
Expand Down Expand Up @@ -584,7 +588,7 @@ export class PrivateKeyStoreDwn implements ManagedKeyStore<string, ManagedPrivat
const authorDid = await this.getAuthor({ agent, context });

// Encode the managed key or key pair as bytes.
const id = randomUuid(); // Generate a random ID.
const id = cryptoUtils.randomUuid(); // Generate a random ID.
const encodedPrivateKey = this.encodeKey({...key, id });

const { reply: { status } } = await agent.dwnManager.processRequest({
Expand Down Expand Up @@ -723,7 +727,7 @@ export class PrivateKeyStoreMemory implements ManagedKeyStore<string, ManagedPri
// The private key material is transferred to the new object, making the original obj.material unusable.
const clonedKey = structuredClone(key, { transfer: [key.material.buffer] }) as ManagedPrivateKey;

clonedKey.id = randomUuid();
clonedKey.id = cryptoUtils.randomUuid();
this.store.set(clonedKey.id, clonedKey);

return clonedKey.id;
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/tech-preview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as didUtils from '@web5/dids/utils';
import { utils as didUtils } from '@web5/dids';

/**
* Dynamically selects up to 2 DWN endpoints that are provided
Expand Down
2 changes: 1 addition & 1 deletion packages/api/tests/record.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {

import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import * as didUtils from '@web5/dids/utils';
import { utils as didUtils } from '@web5/dids';
import { TestManagedAgent } from '@web5/agent';
import {
RecordsWrite,
Expand Down
4 changes: 2 additions & 2 deletions packages/api/tests/utils/test-data-generator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { randomBytes } from '@web5/crypto/utils';
import { utils as cryptoUtils } from '@web5/crypto';

export class TestDataGenerator {
/**
* Generates a random byte array of given length.
*/
static randomBytes(length: number): Uint8Array {
return randomBytes(length);
return cryptoUtils.randomBytes(length);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/dids/src/did-key.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { PrivateKeyJwk, PublicKeyJwk, Web5Crypto } from '@web5/crypto';

import { universalTypeOf } from '@web5/common';
import { keyToMultibaseId, multibaseIdToKey } from '@web5/crypto/utils';
import {
Jose,
Ed25519,
Secp256k1,
EcdsaAlgorithm,
EdDsaAlgorithm,
utils as cryptoUtils,
} from '@web5/crypto';

import type {
Expand All @@ -17,9 +17,9 @@ import type {
VerificationMethod,
DidResolutionResult,
DidResolutionOptions,
DidKeySetVerificationMethodKey,
} from './types.js';

import { DidKeySetVerificationMethodKey } from './types.js';
import { getVerificationMethodTypes, parseDid } from './utils.js';

const SupportedCryptoAlgorithms = [
Expand Down Expand Up @@ -340,7 +340,7 @@ export class DidKeyMethod implements DidMethod {
* base58-btc encoding of the concatenation of the multicodecValue and
* the rawPublicKeyBytes.
*/
const kemMultibaseValue = keyToMultibaseId({
const kemMultibaseValue = cryptoUtils.keyToMultibaseId({
key : rawPublicKeyBytes,
multicodecCode : multicodecValue
});
Expand Down Expand Up @@ -457,7 +457,7 @@ export class DidKeyMethod implements DidMethod {
const {
key: rawPublicKeyBytes,
multicodecCode: multicodecValue
} = multibaseIdToKey({ multibaseKeyId: multibaseValue });
} = cryptoUtils.multibaseIdToKey({ multibaseKeyId: multibaseValue });

/**
* 4. If the multicodecValue is 0xed, derive a public X25519 encryption key
Expand Down Expand Up @@ -516,7 +516,7 @@ export class DidKeyMethod implements DidMethod {
key: rawPublicKeyBytes,
multicodecCode: multicodecValue,
multicodecName
} = multibaseIdToKey({ multibaseKeyId: multibaseValue });
} = cryptoUtils.multibaseIdToKey({ multibaseKeyId: multibaseValue });

/**
* 3. Ensure the proper key length of rawPublicKeyBytes based on the
Expand Down
Loading