Skip to content

Commit 2d0b423

Browse files
authored
cleanup crypto utils (#838)
* cleanup crypto utils (#830) * cleanup crypto utils * changeset * Update index.ts * finish: delete package.json utils export * bump dwn server * fix api bump * Update utils.ts * bump dwn server * maybe fix codecov
1 parent 0862ffc commit 2d0b423

28 files changed

Lines changed: 157 additions & 312 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@web5/crypto-aws-kms": patch
3+
"@web5/identity-agent": patch
4+
"@web5/credentials": patch
5+
"@web5/proxy-agent": patch
6+
"@web5/user-agent": patch
7+
"@web5/crypto": patch
8+
"@web5/agent": patch
9+
"@web5/dids": patch
10+
---
11+
12+
cleanup crypto utils

.github/workflows/tests-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
run: kill $DWN_SERVER_BACKGROUND_PROCESS || true
7373

7474
- name: Upload test coverage to Codecov
75-
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
75+
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 #v4.5.0
7676
env:
7777
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
7878

codecov.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ component_management:
77
- type: project
88
target: auto # auto compares coverage to the previous base commit
99
threshold: 5% # allows a 5% drop from the previous base commit coverage
10+
informational: true
1011
- type: patch
1112
target: 90
13+
informational: true
14+
if_ci_failed: success
1215

1316
individual_components:
1417
- component_id: package-agent

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"@changesets/cli": "^2.27.5",
3232
"@npmcli/package-json": "5.0.0",
3333
"@typescript-eslint/eslint-plugin": "7.9.0",
34-
"@web5/dwn-server": "0.4.6",
34+
"@web5/dwn-server": "0.4.7",
3535
"audit-ci": "^7.0.1",
3636
"eslint-plugin-mocha": "10.4.3",
3737
"globals": "^13.24.0",

packages/agent/src/dwn-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '@tbd54566975/dwn-sdk-js';
1515

1616
import { NodeStream } from '@web5/common';
17-
import { utils as cryptoUtils } from '@web5/crypto';
17+
import { CryptoUtils } from '@web5/crypto';
1818
import { DidDht, DidJwk, DidResolverCacheLevel, UniversalResolver } from '@web5/dids';
1919

2020
import type { Web5PlatformAgent } from './types/agent.js';
@@ -396,7 +396,7 @@ export class AgentDwnApi {
396396
const keyManager = this.agent.keyManager;
397397

398398
return {
399-
algorithm : cryptoUtils.getJoseSignatureAlgorithmFromPublicKey(publicKey),
399+
algorithm : CryptoUtils.getJoseSignatureAlgorithmFromPublicKey(publicKey),
400400
keyId : signingMethod.id,
401401
sign : async (data: Uint8Array) => {
402402
return await keyManager.sign({ data, keyUri: keyUri! });

packages/agent/src/dwn-registrar.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Sha256, utils } from '@web5/crypto';
1+
import { Sha256, CryptoUtils } from '@web5/crypto';
22
import { concatenateUrl } from './utils.js';
33
import { Convert } from '@web5/common';
44

@@ -120,8 +120,8 @@ export class DwnRegistrar {
120120
* Generates 32 random bytes expressed as a HEX string.
121121
*/
122122
public static async generateNonce(): Promise<string> {
123-
const randomBytes = utils.randomBytes(32);
124-
const hexString = await Convert.uint8Array(randomBytes).toHex().toUpperCase();
123+
const randomBytes = CryptoUtils.randomBytes(32);
124+
const hexString = Convert.uint8Array(randomBytes).toHex().toUpperCase();
125125
return hexString;
126126
}
127127
}

packages/agent/src/prototyping/clients/http-dwn-rpc-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { JsonRpcResponse } from './json-rpc.js';
22
import type { DwnRpc, DwnRpcRequest, DwnRpcResponse } from './dwn-rpc-types.js';
33

44
import { createJsonRpcRequest, parseJson } from './json-rpc.js';
5-
import { utils as cryptoUtils } from '@web5/crypto';
5+
import { CryptoUtils } from '@web5/crypto';
66
import { DwnServerInfoCache, ServerInfo } from './server-info-types.js';
77
import { DwnServerInfoCacheMemory } from './dwn-server-info-cache-memory.js';
88

@@ -18,7 +18,7 @@ export class HttpDwnRpcClient implements DwnRpc {
1818
get transportProtocols() { return ['http:', 'https:']; }
1919

2020
async sendDwnRequest(request: DwnRpcRequest): Promise<DwnRpcResponse> {
21-
const requestId = cryptoUtils.randomUuid();
21+
const requestId = CryptoUtils.randomUuid();
2222
const jsonRpcRequest = createJsonRpcRequest(requestId, 'dwn.processMessage', {
2323
target : request.targetDid,
2424
message : request.message

packages/agent/src/prototyping/clients/json-rpc-socket.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { utils as cryptoUtils } from '@web5/crypto';
1+
import { CryptoUtils } from '@web5/crypto';
22
import IsomorphicWebSocket from 'isomorphic-ws';
33
import { JsonRpcId, JsonRpcRequest, JsonRpcResponse, createJsonRpcSubscriptionRequest, parseJson } from './json-rpc.js';
44

@@ -81,7 +81,7 @@ export class JsonRpcSocket {
8181
*/
8282
async request(request: JsonRpcRequest): Promise<JsonRpcResponse> {
8383
return new Promise((resolve, reject) => {
84-
request.id ??= cryptoUtils.randomUuid();
84+
request.id ??= CryptoUtils.randomUuid();
8585

8686
const handleResponse = (event: { data: any }):void => {
8787
const jsonRpsResponse = parseJson(event.data) as JsonRpcResponse;
@@ -155,7 +155,7 @@ export class JsonRpcSocket {
155155
}
156156

157157
private closeSubscription(id: JsonRpcId): Promise<JsonRpcResponse> {
158-
const requestId = cryptoUtils.randomUuid();
158+
const requestId = CryptoUtils.randomUuid();
159159
const request = createJsonRpcSubscriptionRequest(requestId, 'close', id, {});
160160
return this.request(request);
161161
}

packages/agent/src/prototyping/clients/web-socket-clients.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { DwnRpc, DwnRpcRequest, DwnRpcResponse, DwnSubscriptionHandler } from './dwn-rpc-types.js';
22
import type { GenericMessage, MessageSubscription, UnionMessageReply } from '@tbd54566975/dwn-sdk-js';
33

4-
import { utils as cryptoUtils } from '@web5/crypto';
4+
import { CryptoUtils } from '@web5/crypto';
55
import { createJsonRpcRequest, createJsonRpcSubscriptionRequest } from './json-rpc.js';
66
import { JsonRpcSocket, JsonRpcSocketOptions } from './json-rpc-socket.js';
77

@@ -46,7 +46,7 @@ export class WebSocketDwnRpcClient implements DwnRpc {
4646
}
4747

4848
private static async processMessage(connection: SocketConnection, target: string, message: GenericMessage): Promise<DwnRpcResponse> {
49-
const requestId = cryptoUtils.randomUuid();
49+
const requestId = CryptoUtils.randomUuid();
5050
const request = createJsonRpcRequest(requestId, 'dwn.processMessage', { target, message });
5151

5252
const { socket } = connection;
@@ -61,8 +61,8 @@ export class WebSocketDwnRpcClient implements DwnRpc {
6161
}
6262

6363
private static async subscriptionRequest(connection: SocketConnection, target:string, message: GenericMessage, messageHandler: DwnSubscriptionHandler): Promise<DwnRpcResponse> {
64-
const requestId = cryptoUtils.randomUuid();
65-
const subscriptionId = cryptoUtils.randomUuid();
64+
const requestId = CryptoUtils.randomUuid();
65+
const subscriptionId = CryptoUtils.randomUuid();
6666
const request = createJsonRpcSubscriptionRequest(requestId, 'dwn.processMessage', subscriptionId, { target, message });
6767

6868
const { socket, subscriptions } = connection;

packages/agent/src/prototyping/crypto/jose/jwe-flattened.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Jwk, KeyIdentifier } from '@web5/crypto';
22

33
import { Convert } from '@web5/common';
4-
import { LocalKeyManager, utils as cryptoUtils } from '@web5/crypto';
4+
import { LocalKeyManager, CryptoUtils } from '@web5/crypto';
55

66
import type { CryptoApi } from '../types/crypto-api.js';
77
import type { KeyManager } from '../types/key-manager.js';
@@ -404,7 +404,7 @@ export class FlattenedJwe {
404404
case 'A128GCM':
405405
case 'A192GCM':
406406
case 'A256GCM':
407-
iv = cryptoUtils.randomBytes(12);
407+
iv = CryptoUtils.randomBytes(12);
408408
break;
409409
default:
410410
iv = new Uint8Array(0);

0 commit comments

Comments
 (0)