@enbox/agent 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.mjs +45 -52
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/crypto-api.js +6 -13
- package/dist/esm/crypto-api.js.map +1 -1
- package/dist/esm/dwn-api.js +80 -78
- package/dist/esm/dwn-api.js.map +1 -1
- package/dist/esm/hd-identity-vault.js +4 -5
- package/dist/esm/hd-identity-vault.js.map +1 -1
- package/dist/esm/identity-api.js +1 -1
- package/dist/esm/identity-api.js.map +1 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/local-key-manager.js +31 -32
- package/dist/esm/local-key-manager.js.map +1 -1
- package/dist/esm/prototyping/crypto/jose/jwe-compact.js +1 -2
- package/dist/esm/prototyping/crypto/jose/jwe-compact.js.map +1 -1
- package/dist/esm/prototyping/crypto/jose/jwe-flattened.js +15 -4
- package/dist/esm/prototyping/crypto/jose/jwe-flattened.js.map +1 -1
- package/dist/esm/prototyping/crypto/jose/jwe.js +1 -1
- package/dist/esm/prototyping/crypto/jose/jwe.js.map +1 -1
- package/dist/esm/store-data.js +3 -3
- package/dist/esm/store-data.js.map +1 -1
- package/dist/esm/store-did.js +1 -1
- package/dist/esm/store-did.js.map +1 -1
- package/dist/esm/sync-engine-level.js +49 -11
- package/dist/esm/sync-engine-level.js.map +1 -1
- package/dist/esm/test-harness.js +24 -8
- package/dist/esm/test-harness.js.map +1 -1
- package/dist/esm/types/dwn.js +1 -1
- package/dist/esm/types/dwn.js.map +1 -1
- package/dist/esm/web5-user-agent.js +1 -1
- package/dist/esm/web5-user-agent.js.map +1 -1
- package/dist/types/crypto-api.d.ts +8 -12
- package/dist/types/crypto-api.d.ts.map +1 -1
- package/dist/types/dwn-api.d.ts +10 -10
- package/dist/types/dwn-api.d.ts.map +1 -1
- package/dist/types/hd-identity-vault.d.ts.map +1 -1
- package/dist/types/identity-api.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/local-key-manager.d.ts +15 -18
- package/dist/types/local-key-manager.d.ts.map +1 -1
- package/dist/types/prototyping/crypto/jose/jwe-compact.d.ts +1 -3
- package/dist/types/prototyping/crypto/jose/jwe-compact.d.ts.map +1 -1
- package/dist/types/prototyping/crypto/jose/jwe-flattened.d.ts +1 -3
- package/dist/types/prototyping/crypto/jose/jwe-flattened.d.ts.map +1 -1
- package/dist/types/prototyping/crypto/jose/jwe.d.ts +1 -3
- package/dist/types/prototyping/crypto/jose/jwe.d.ts.map +1 -1
- package/dist/types/store-data.d.ts +2 -2
- package/dist/types/store-did.d.ts.map +1 -1
- package/dist/types/sync-engine-level.d.ts +18 -6
- package/dist/types/sync-engine-level.d.ts.map +1 -1
- package/dist/types/test-harness.d.ts.map +1 -1
- package/dist/types/types/agent.d.ts +1 -1
- package/dist/types/types/agent.d.ts.map +1 -1
- package/dist/types/types/dwn.d.ts +2 -2
- package/dist/types/types/dwn.d.ts.map +1 -1
- package/dist/types/types/key-manager.d.ts +15 -22
- package/dist/types/types/key-manager.d.ts.map +1 -1
- package/dist/types/utils-internal.d.ts +1 -1
- package/dist/types/utils-internal.d.ts.map +1 -1
- package/dist/types/web5-user-agent.d.ts +1 -1
- package/dist/types/web5-user-agent.d.ts.map +1 -1
- package/package.json +10 -12
- package/src/crypto-api.ts +24 -20
- package/src/dwn-api.ts +109 -102
- package/src/hd-identity-vault.ts +4 -5
- package/src/identity-api.ts +2 -1
- package/src/index.ts +0 -2
- package/src/local-key-manager.ts +43 -44
- package/src/prototyping/crypto/jose/jwe-compact.ts +3 -7
- package/src/prototyping/crypto/jose/jwe-flattened.ts +20 -9
- package/src/prototyping/crypto/jose/jwe.ts +2 -6
- package/src/store-data.ts +3 -3
- package/src/store-did.ts +1 -1
- package/src/sync-engine-level.ts +59 -16
- package/src/test-harness.ts +23 -8
- package/src/types/agent.ts +1 -1
- package/src/types/dwn.ts +2 -2
- package/src/types/key-manager.ts +31 -22
- package/src/utils-internal.ts +1 -1
- package/src/web5-user-agent.ts +2 -2
- package/dist/browser.js +0 -2213
- package/dist/browser.js.map +0 -7
- package/dist/esm/dwn-registrar.js +0 -120
- package/dist/esm/dwn-registrar.js.map +0 -1
- package/dist/esm/prototyping/clients/dwn-rpc-types.js +0 -2
- package/dist/esm/prototyping/clients/dwn-rpc-types.js.map +0 -1
- package/dist/esm/prototyping/clients/dwn-server-info-cache-memory.js +0 -74
- package/dist/esm/prototyping/clients/dwn-server-info-cache-memory.js.map +0 -1
- package/dist/esm/prototyping/clients/http-dwn-rpc-client.js +0 -112
- package/dist/esm/prototyping/clients/http-dwn-rpc-client.js.map +0 -1
- package/dist/esm/prototyping/clients/json-rpc-socket.js +0 -167
- package/dist/esm/prototyping/clients/json-rpc-socket.js.map +0 -1
- package/dist/esm/prototyping/clients/json-rpc.js +0 -58
- package/dist/esm/prototyping/clients/json-rpc.js.map +0 -1
- package/dist/esm/prototyping/clients/server-info-types.js +0 -2
- package/dist/esm/prototyping/clients/server-info-types.js.map +0 -1
- package/dist/esm/prototyping/clients/web-socket-clients.js +0 -90
- package/dist/esm/prototyping/clients/web-socket-clients.js.map +0 -1
- package/dist/esm/prototyping/common/object.js +0 -14
- package/dist/esm/prototyping/common/object.js.map +0 -1
- package/dist/esm/prototyping/common/type-utils.js +0 -2
- package/dist/esm/prototyping/common/type-utils.js.map +0 -1
- package/dist/esm/prototyping/crypto/algorithms/aes-gcm.js +0 -147
- package/dist/esm/prototyping/crypto/algorithms/aes-gcm.js.map +0 -1
- package/dist/esm/prototyping/crypto/algorithms/aes-kw.js +0 -136
- package/dist/esm/prototyping/crypto/algorithms/aes-kw.js.map +0 -1
- package/dist/esm/prototyping/crypto/algorithms/ecdsa.js +0 -311
- package/dist/esm/prototyping/crypto/algorithms/ecdsa.js.map +0 -1
- package/dist/esm/prototyping/crypto/algorithms/eddsa.js +0 -268
- package/dist/esm/prototyping/crypto/algorithms/eddsa.js.map +0 -1
- package/dist/esm/prototyping/crypto/algorithms/hkdf.js +0 -38
- package/dist/esm/prototyping/crypto/algorithms/hkdf.js.map +0 -1
- package/dist/esm/prototyping/crypto/algorithms/pbkdf2.js +0 -40
- package/dist/esm/prototyping/crypto/algorithms/pbkdf2.js.map +0 -1
- package/dist/esm/prototyping/crypto/crypto-error.js +0 -41
- package/dist/esm/prototyping/crypto/crypto-error.js.map +0 -1
- package/dist/esm/prototyping/crypto/types/crypto-api.js +0 -2
- package/dist/esm/prototyping/crypto/types/crypto-api.js.map +0 -1
- package/dist/esm/prototyping/crypto/types/key-converter.js +0 -2
- package/dist/esm/prototyping/crypto/types/key-converter.js.map +0 -1
- package/dist/esm/prototyping/crypto/types/key-deriver.js +0 -2
- package/dist/esm/prototyping/crypto/types/key-deriver.js.map +0 -1
- package/dist/esm/prototyping/crypto/types/key-io.js +0 -2
- package/dist/esm/prototyping/crypto/types/key-io.js.map +0 -1
- package/dist/esm/prototyping/crypto/types/key-manager.js +0 -2
- package/dist/esm/prototyping/crypto/types/key-manager.js.map +0 -1
- package/dist/esm/prototyping/crypto/types/params-direct.js +0 -2
- package/dist/esm/prototyping/crypto/types/params-direct.js.map +0 -1
- package/dist/esm/prototyping/crypto/types/params-kms.js +0 -2
- package/dist/esm/prototyping/crypto/types/params-kms.js.map +0 -1
- package/dist/esm/prototyping/crypto/utils.js +0 -19
- package/dist/esm/prototyping/crypto/utils.js.map +0 -1
- package/dist/esm/prototyping/dids/resolver-cache-memory.js +0 -77
- package/dist/esm/prototyping/dids/resolver-cache-memory.js.map +0 -1
- package/dist/esm/prototyping/dids/utils.js +0 -9
- package/dist/esm/prototyping/dids/utils.js.map +0 -1
- package/dist/esm/rpc-client.js +0 -123
- package/dist/esm/rpc-client.js.map +0 -1
- package/dist/types/dwn-registrar.d.ts +0 -29
- package/dist/types/dwn-registrar.d.ts.map +0 -1
- package/dist/types/prototyping/clients/dwn-rpc-types.d.ts +0 -45
- package/dist/types/prototyping/clients/dwn-rpc-types.d.ts.map +0 -1
- package/dist/types/prototyping/clients/dwn-server-info-cache-memory.d.ts +0 -57
- package/dist/types/prototyping/clients/dwn-server-info-cache-memory.d.ts.map +0 -1
- package/dist/types/prototyping/clients/http-dwn-rpc-client.d.ts +0 -13
- package/dist/types/prototyping/clients/http-dwn-rpc-client.d.ts.map +0 -1
- package/dist/types/prototyping/clients/json-rpc-socket.d.ts +0 -43
- package/dist/types/prototyping/clients/json-rpc-socket.d.ts.map +0 -1
- package/dist/types/prototyping/clients/json-rpc.d.ts +0 -49
- package/dist/types/prototyping/clients/json-rpc.d.ts.map +0 -1
- package/dist/types/prototyping/clients/server-info-types.d.ts +0 -20
- package/dist/types/prototyping/clients/server-info-types.d.ts.map +0 -1
- package/dist/types/prototyping/clients/web-socket-clients.d.ts +0 -10
- package/dist/types/prototyping/clients/web-socket-clients.d.ts.map +0 -1
- package/dist/types/prototyping/common/object.d.ts +0 -2
- package/dist/types/prototyping/common/object.d.ts.map +0 -1
- package/dist/types/prototyping/common/type-utils.d.ts +0 -7
- package/dist/types/prototyping/common/type-utils.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/algorithms/aes-gcm.d.ts +0 -151
- package/dist/types/prototyping/crypto/algorithms/aes-gcm.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/algorithms/aes-kw.d.ts +0 -108
- package/dist/types/prototyping/crypto/algorithms/aes-kw.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/algorithms/ecdsa.d.ts +0 -160
- package/dist/types/prototyping/crypto/algorithms/ecdsa.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/algorithms/eddsa.d.ts +0 -157
- package/dist/types/prototyping/crypto/algorithms/eddsa.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/algorithms/hkdf.d.ts +0 -20
- package/dist/types/prototyping/crypto/algorithms/hkdf.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/algorithms/pbkdf2.d.ts +0 -20
- package/dist/types/prototyping/crypto/algorithms/pbkdf2.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/crypto-error.d.ts +0 -29
- package/dist/types/prototyping/crypto/crypto-error.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/types/crypto-api.d.ts +0 -34
- package/dist/types/prototyping/crypto/types/crypto-api.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/types/key-converter.d.ts +0 -49
- package/dist/types/prototyping/crypto/types/key-converter.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/types/key-deriver.d.ts +0 -50
- package/dist/types/prototyping/crypto/types/key-deriver.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/types/key-io.d.ts +0 -49
- package/dist/types/prototyping/crypto/types/key-io.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/types/key-manager.d.ts +0 -69
- package/dist/types/prototyping/crypto/types/key-manager.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/types/params-direct.d.ts +0 -75
- package/dist/types/prototyping/crypto/types/params-direct.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/types/params-kms.d.ts +0 -63
- package/dist/types/prototyping/crypto/types/params-kms.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/utils.d.ts +0 -7
- package/dist/types/prototyping/crypto/utils.d.ts.map +0 -1
- package/dist/types/prototyping/dids/resolver-cache-memory.d.ts +0 -57
- package/dist/types/prototyping/dids/resolver-cache-memory.d.ts.map +0 -1
- package/dist/types/prototyping/dids/utils.d.ts +0 -3
- package/dist/types/prototyping/dids/utils.d.ts.map +0 -1
- package/dist/types/rpc-client.d.ts +0 -51
- package/dist/types/rpc-client.d.ts.map +0 -1
- package/src/dwn-registrar.ts +0 -127
- package/src/prototyping/clients/dwn-rpc-types.ts +0 -55
- package/src/prototyping/clients/dwn-server-info-cache-memory.ts +0 -79
- package/src/prototyping/clients/http-dwn-rpc-client.ts +0 -119
- package/src/prototyping/clients/json-rpc-socket.ts +0 -189
- package/src/prototyping/clients/json-rpc.ts +0 -113
- package/src/prototyping/clients/server-info-types.ts +0 -21
- package/src/prototyping/clients/web-socket-clients.ts +0 -103
- package/src/prototyping/common/object.ts +0 -15
- package/src/prototyping/common/type-utils.ts +0 -6
- package/src/prototyping/crypto/algorithms/aes-gcm.ts +0 -211
- package/src/prototyping/crypto/algorithms/aes-kw.ts +0 -160
- package/src/prototyping/crypto/algorithms/ecdsa.ts +0 -366
- package/src/prototyping/crypto/algorithms/eddsa.ts +0 -311
- package/src/prototyping/crypto/algorithms/hkdf.ts +0 -38
- package/src/prototyping/crypto/algorithms/pbkdf2.ts +0 -41
- package/src/prototyping/crypto/crypto-error.ts +0 -45
- package/src/prototyping/crypto/types/crypto-api.ts +0 -77
- package/src/prototyping/crypto/types/key-converter.ts +0 -53
- package/src/prototyping/crypto/types/key-deriver.ts +0 -56
- package/src/prototyping/crypto/types/key-io.ts +0 -51
- package/src/prototyping/crypto/types/key-manager.ts +0 -83
- package/src/prototyping/crypto/types/params-direct.ts +0 -95
- package/src/prototyping/crypto/types/params-kms.ts +0 -76
- package/src/prototyping/crypto/utils.ts +0 -41
- package/src/prototyping/dids/resolver-cache-memory.ts +0 -83
- package/src/prototyping/dids/utils.ts +0 -10
- package/src/rpc-client.ts +0 -160
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { CryptoUtils } from '@enbox/crypto';
|
|
11
|
-
import { JsonRpcSocket } from './json-rpc-socket.js';
|
|
12
|
-
import { createJsonRpcRequest, createJsonRpcSubscriptionRequest } from './json-rpc.js';
|
|
13
|
-
export class WebSocketDwnRpcClient {
|
|
14
|
-
get transportProtocols() { return ['ws:', 'wss:']; }
|
|
15
|
-
sendDwnRequest(request, jsonRpcSocketOptions) {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
// validate that the dwn URL provided is a valid WebSocket URL
|
|
18
|
-
const url = new URL(request.dwnUrl);
|
|
19
|
-
if (url.protocol !== 'ws:' && url.protocol !== 'wss:') {
|
|
20
|
-
throw new Error(`Invalid websocket protocol ${url.protocol}`);
|
|
21
|
-
}
|
|
22
|
-
// check if there is already a connection to this host, if it does not exist, initiate a new connection
|
|
23
|
-
const hasConnection = WebSocketDwnRpcClient.connections.has(url.host);
|
|
24
|
-
if (!hasConnection) {
|
|
25
|
-
try {
|
|
26
|
-
const socket = yield JsonRpcSocket.connect(url.toString(), jsonRpcSocketOptions);
|
|
27
|
-
const subscriptions = new Map();
|
|
28
|
-
WebSocketDwnRpcClient.connections.set(url.host, { socket, subscriptions });
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
throw new Error(`Error connecting to ${url.host}: ${error.message}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
const connection = WebSocketDwnRpcClient.connections.get(url.host);
|
|
35
|
-
const { targetDid, message, subscriptionHandler } = request;
|
|
36
|
-
if (subscriptionHandler) {
|
|
37
|
-
return WebSocketDwnRpcClient.subscriptionRequest(connection, targetDid, message, subscriptionHandler);
|
|
38
|
-
}
|
|
39
|
-
return WebSocketDwnRpcClient.processMessage(connection, targetDid, message);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
static processMessage(connection, target, message) {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const requestId = CryptoUtils.randomUuid();
|
|
45
|
-
const request = createJsonRpcRequest(requestId, 'dwn.processMessage', { target, message });
|
|
46
|
-
const { socket } = connection;
|
|
47
|
-
const response = yield socket.request(request);
|
|
48
|
-
const { error, result } = response;
|
|
49
|
-
if (error !== undefined) {
|
|
50
|
-
throw new Error(`error sending DWN request: ${error.message}`);
|
|
51
|
-
}
|
|
52
|
-
return result.reply;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
static subscriptionRequest(connection, target, message, messageHandler) {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
const requestId = CryptoUtils.randomUuid();
|
|
58
|
-
const subscriptionId = CryptoUtils.randomUuid();
|
|
59
|
-
const request = createJsonRpcSubscriptionRequest(requestId, 'dwn.processMessage', subscriptionId, { target, message });
|
|
60
|
-
const { socket, subscriptions } = connection;
|
|
61
|
-
const { response, close } = yield socket.subscribe(request, (response) => {
|
|
62
|
-
const { result, error } = response;
|
|
63
|
-
if (error) {
|
|
64
|
-
// if there is an error, close the subscription and delete it from the connection
|
|
65
|
-
const subscription = subscriptions.get(subscriptionId);
|
|
66
|
-
if (subscription) {
|
|
67
|
-
subscription.close();
|
|
68
|
-
}
|
|
69
|
-
subscriptions.delete(subscriptionId);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const { event } = result;
|
|
73
|
-
messageHandler(event);
|
|
74
|
-
});
|
|
75
|
-
const { error, result } = response;
|
|
76
|
-
if (error) {
|
|
77
|
-
throw new Error(`could not subscribe via jsonrpc socket: ${error.message}`);
|
|
78
|
-
}
|
|
79
|
-
const { reply } = result;
|
|
80
|
-
if (reply.subscription && close) {
|
|
81
|
-
subscriptions.set(subscriptionId, Object.assign(Object.assign({}, reply.subscription), { close }));
|
|
82
|
-
reply.subscription.close = close;
|
|
83
|
-
}
|
|
84
|
-
return reply;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
// a map of dwn host to WebSocket connection
|
|
89
|
-
WebSocketDwnRpcClient.connections = new Map();
|
|
90
|
-
//# sourceMappingURL=web-socket-clients.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"web-socket-clients.js","sourceRoot":"","sources":["../../../../src/prototyping/clients/web-socket-clients.ts"],"names":[],"mappings":";;;;;;;;;AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,gCAAgC,EAAE,MAAM,eAAe,CAAC;AAOvF,MAAM,OAAO,qBAAqB;IAChC,IAAW,kBAAkB,KAAe,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAI/D,cAAc,CAAC,OAAsB,EAAE,oBAA2C;;YAEtF,8DAA8D;YAC9D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACpC,IAAI,GAAG,CAAC,QAAQ,KAAK,KAAK,IAAI,GAAG,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;gBACtD,MAAM,IAAI,KAAK,CAAC,8BAA8B,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YAChE,CAAC;YAED,uGAAuG;YACvG,MAAM,aAAa,GAAG,qBAAqB,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACtE,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,IAAI,CAAC;oBACH,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,oBAAoB,CAAC,CAAC;oBACjF,MAAM,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;oBAChC,qBAAqB,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;gBAC7E,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,IAAI,KAAK,C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AAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC;KAAA;;AAtFD,4CAA4C;AAC7B,iCAAW,GAAG,IAAI,GAAG,EAA4B,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function hasDuplicateProperties(...objects) {
|
|
2
|
-
const propertySet = new Set();
|
|
3
|
-
const objectsWithoutUndefined = objects.filter(Boolean); // Remove any undefined values
|
|
4
|
-
for (const obj of objectsWithoutUndefined) {
|
|
5
|
-
for (const key in obj) {
|
|
6
|
-
if (propertySet.has(key)) {
|
|
7
|
-
return true; // Return true if a duplicate property is found
|
|
8
|
-
}
|
|
9
|
-
propertySet.add(key);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return false; // Return false if no duplicates are found
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=object.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../../../src/prototyping/common/object.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,sBAAsB,CAAC,GAAG,OAA+C;IACvF,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;IACtC,MAAM,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,8BAA8B;IAEvF,KAAK,MAAM,GAAG,IAAI,uBAAuB,EAAE,CAAC;QAC1C,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;YACtB,IAAI,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC,CAAC,+CAA+C;YAC9D,CAAC;YACD,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,CAAC,0CAA0C;AAC1D,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type-utils.js","sourceRoot":"","sources":["../../../../src/prototyping/common/type-utils.ts"],"names":[],"mappings":""}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { AesGcm, CryptoAlgorithm } from '@enbox/crypto';
|
|
11
|
-
/**
|
|
12
|
-
* The `AesGcmAlgorithm` class provides a concrete implementation for cryptographic operations using
|
|
13
|
-
* the AES algorithm in Galois/Counter Mode (GCM). This class implements both
|
|
14
|
-
* {@link Cipher | `Cipher`} and { @link KeyGenerator | `KeyGenerator`} interfaces, providing
|
|
15
|
-
* key generation, encryption, and decryption features.
|
|
16
|
-
*
|
|
17
|
-
* This class is typically accessed through implementations that extend the
|
|
18
|
-
* {@link CryptoApi | `CryptoApi`} interface.
|
|
19
|
-
*/
|
|
20
|
-
export class AesGcmAlgorithm extends CryptoAlgorithm {
|
|
21
|
-
bytesToPrivateKey(_a) {
|
|
22
|
-
return __awaiter(this, arguments, void 0, function* ({ privateKeyBytes }) {
|
|
23
|
-
// Convert the byte array to a JWK.
|
|
24
|
-
const privateKey = yield AesGcm.bytesToPrivateKey({ privateKeyBytes });
|
|
25
|
-
// Set the `alg` property based on the key length.
|
|
26
|
-
privateKey.alg = { 16: 'A128GCM', 24: 'A192GCM', 32: 'A256GCM' }[privateKeyBytes.length];
|
|
27
|
-
return privateKey;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Decrypts the provided data using AES-GCM.
|
|
32
|
-
*
|
|
33
|
-
* @remarks
|
|
34
|
-
* This method performs AES-GCM decryption on the given encrypted data using the specified key.
|
|
35
|
-
* It requires an initialization vector (IV), the encrypted data along with the decryption key,
|
|
36
|
-
* and optionally, additional authenticated data (AAD). The method returns the decrypted data as a
|
|
37
|
-
* Uint8Array. The optional `tagLength` parameter specifies the size in bits of the authentication
|
|
38
|
-
* tag used when encrypting the data. If not specified, the default tag length of 128 bits is
|
|
39
|
-
* used.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```ts
|
|
43
|
-
* const aesGcm = new AesGcmAlgorithm();
|
|
44
|
-
* const encryptedData = new Uint8Array([...]); // Encrypted data
|
|
45
|
-
* const iv = new Uint8Array([...]); // Initialization vector used during encryption
|
|
46
|
-
* const additionalData = new Uint8Array([...]); // Optional additional authenticated data
|
|
47
|
-
* const key = { ... }; // A Jwk object representing the AES key
|
|
48
|
-
* const decryptedData = await aesGcm.decrypt({
|
|
49
|
-
* data: encryptedData,
|
|
50
|
-
* iv,
|
|
51
|
-
* additionalData,
|
|
52
|
-
* key,
|
|
53
|
-
* tagLength: 128 // Optional tag length in bits
|
|
54
|
-
* });
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* @param params - The parameters for the decryption operation.
|
|
58
|
-
*
|
|
59
|
-
* @returns A Promise that resolves to the decrypted data as a Uint8Array.
|
|
60
|
-
*/
|
|
61
|
-
decrypt(params) {
|
|
62
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
const plaintext = AesGcm.decrypt(params);
|
|
64
|
-
return plaintext;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Encrypts the provided data using AES-GCM.
|
|
69
|
-
*
|
|
70
|
-
* @remarks
|
|
71
|
-
* This method performs AES-GCM encryption on the given data using the specified key.
|
|
72
|
-
* It requires an initialization vector (IV), the encrypted data along with the decryption key,
|
|
73
|
-
* and optionally, additional authenticated data (AAD). The method returns the encrypted data as a
|
|
74
|
-
* Uint8Array. The optional `tagLength` parameter specifies the size in bits of the authentication
|
|
75
|
-
* tag generated in the encryption operation and used for authentication in the corresponding
|
|
76
|
-
* decryption. If not specified, the default tag length of 128 bits is used.
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```ts
|
|
80
|
-
* const aesGcm = new AesGcmAlgorithm();
|
|
81
|
-
* const data = new TextEncoder().encode('Messsage');
|
|
82
|
-
* const iv = new Uint8Array([...]); // Initialization vector
|
|
83
|
-
* const additionalData = new Uint8Array([...]); // Optional additional authenticated data
|
|
84
|
-
* const key = { ... }; // A Jwk object representing an AES key
|
|
85
|
-
* const encryptedData = await aesGcm.encrypt({
|
|
86
|
-
* data,
|
|
87
|
-
* iv,
|
|
88
|
-
* additionalData,
|
|
89
|
-
* key,
|
|
90
|
-
* tagLength: 128 // Optional tag length in bits
|
|
91
|
-
* });
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* @param params - The parameters for the encryption operation.
|
|
95
|
-
*
|
|
96
|
-
* @returns A Promise that resolves to the encrypted data as a Uint8Array.
|
|
97
|
-
*/
|
|
98
|
-
encrypt(params) {
|
|
99
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
-
const ciphertext = AesGcm.encrypt(params);
|
|
101
|
-
return ciphertext;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Generates a symmetric key for AES in Galois/Counter Mode (GCM) in JSON Web Key (JWK) format.
|
|
106
|
-
*
|
|
107
|
-
* @remarks
|
|
108
|
-
* This method generates a symmetric AES key for use in GCM mode, based on the specified
|
|
109
|
-
* `algorithm` parameter which determines the key length. It uses cryptographically secure random
|
|
110
|
-
* number generation to ensure the uniqueness and security of the key. The key is returned in JWK
|
|
111
|
-
* format.
|
|
112
|
-
*
|
|
113
|
-
* The generated key includes the following components:
|
|
114
|
-
* - `kty`: Key Type, set to 'oct' for Octet Sequence.
|
|
115
|
-
* - `k`: The symmetric key component, base64url-encoded.
|
|
116
|
-
* - `kid`: Key ID, generated based on the JWK thumbprint.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```ts
|
|
120
|
-
* const aesGcm = new AesGcmAlgorithm();
|
|
121
|
-
* const privateKey = await aesGcm.generateKey({ algorithm: 'A256GCM' });
|
|
122
|
-
* ```
|
|
123
|
-
*
|
|
124
|
-
* @param params - The parameters for the key generation.
|
|
125
|
-
*
|
|
126
|
-
* @returns A Promise that resolves to the generated symmetric key in JWK format.
|
|
127
|
-
*/
|
|
128
|
-
generateKey(_a) {
|
|
129
|
-
return __awaiter(this, arguments, void 0, function* ({ algorithm }) {
|
|
130
|
-
// Map algorithm name to key length.
|
|
131
|
-
const length = { A128GCM: 128, A192GCM: 192, A256GCM: 256 }[algorithm];
|
|
132
|
-
// Generate a random private key.
|
|
133
|
-
const privateKey = yield AesGcm.generateKey({ length });
|
|
134
|
-
// Set the `alg` property based on the specified algorithm.
|
|
135
|
-
privateKey.alg = algorithm;
|
|
136
|
-
return privateKey;
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
privateKeyToBytes(_a) {
|
|
140
|
-
return __awaiter(this, arguments, void 0, function* ({ privateKey }) {
|
|
141
|
-
// Convert the JWK to a byte array.
|
|
142
|
-
const privateKeyBytes = yield AesGcm.privateKeyToBytes({ privateKey });
|
|
143
|
-
return privateKeyBytes;
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
//# sourceMappingURL=aes-gcm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aes-gcm.js","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/algorithms/aes-gcm.ts"],"names":[],"mappings":";;;;;;;;;AAUA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAqDxD;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAgB,SAAQ,eAAe;IAKrC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AAE,UAAU,EAAE,CAAC,CAAC;YAEvE,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;CACF"}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { AesKw, CryptoAlgorithm } from '@enbox/crypto';
|
|
11
|
-
/**
|
|
12
|
-
* The `AesKwAlgorithm` class provides a concrete implementation for cryptographic operations using
|
|
13
|
-
* the AES algorithm for key wrapping. This class implements both
|
|
14
|
-
* {@link KeyGenerator | `KeyGenerator`} and {@link KeyWrapper | `KeyWrapper`} interfaces, providing
|
|
15
|
-
* key generation, key wrapping, and key unwrapping features.
|
|
16
|
-
*
|
|
17
|
-
* This class is typically accessed through implementations that extend the
|
|
18
|
-
* {@link CryptoApi | `CryptoApi`} interface.
|
|
19
|
-
*/
|
|
20
|
-
export class AesKwAlgorithm extends CryptoAlgorithm {
|
|
21
|
-
bytesToPrivateKey(_a) {
|
|
22
|
-
return __awaiter(this, arguments, void 0, function* ({ privateKeyBytes }) {
|
|
23
|
-
// Convert the byte array to a JWK.
|
|
24
|
-
const privateKey = yield AesKw.bytesToPrivateKey({ privateKeyBytes });
|
|
25
|
-
// Set the `alg` property based on the key length.
|
|
26
|
-
privateKey.alg = { 16: 'A128KW', 24: 'A192KW', 32: 'A256KW' }[privateKeyBytes.length];
|
|
27
|
-
return privateKey;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Generates a symmetric key for AES for key wrapping in JSON Web Key (JWK) format.
|
|
32
|
-
*
|
|
33
|
-
* @remarks
|
|
34
|
-
* This method generates a symmetric AES key for use in key wrapping mode, based on the specified
|
|
35
|
-
* `algorithm` parameter which determines the key length. It uses cryptographically secure random
|
|
36
|
-
* number generation to ensure the uniqueness and security of the key. The key is returned in JWK
|
|
37
|
-
* format.
|
|
38
|
-
*
|
|
39
|
-
* The generated key includes the following components:
|
|
40
|
-
* - `kty`: Key Type, set to 'oct' for Octet Sequence.
|
|
41
|
-
* - `k`: The symmetric key component, base64url-encoded.
|
|
42
|
-
* - `kid`: Key ID, generated based on the JWK thumbprint.
|
|
43
|
-
* - `alg`: Algorithm, set to 'A128KW', 'A192KW', or 'A256KW' for AES Key Wrap with the
|
|
44
|
-
* specified key length.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* const aesKw = new AesKwAlgorithm();
|
|
49
|
-
* const privateKey = await aesKw.generateKey({ algorithm: 'A256KW' });
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @param params - The parameters for the key generation.
|
|
53
|
-
*
|
|
54
|
-
* @returns A Promise that resolves to the generated symmetric key in JWK format.
|
|
55
|
-
*/
|
|
56
|
-
generateKey(_a) {
|
|
57
|
-
return __awaiter(this, arguments, void 0, function* ({ algorithm }) {
|
|
58
|
-
// Map algorithm name to key length.
|
|
59
|
-
const length = { A128KW: 128, A192KW: 192, A256KW: 256 }[algorithm];
|
|
60
|
-
// Generate a random private key.
|
|
61
|
-
const privateKey = yield AesKw.generateKey({ length });
|
|
62
|
-
// Set the `alg` property based on the specified algorithm.
|
|
63
|
-
privateKey.alg = algorithm;
|
|
64
|
-
return privateKey;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
privateKeyToBytes(_a) {
|
|
68
|
-
return __awaiter(this, arguments, void 0, function* ({ privateKey }) {
|
|
69
|
-
// Convert the JWK to a byte array.
|
|
70
|
-
const privateKeyBytes = yield AesKw.privateKeyToBytes({ privateKey });
|
|
71
|
-
return privateKeyBytes;
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Decrypts a wrapped key using the AES Key Wrap algorithm.
|
|
76
|
-
*
|
|
77
|
-
* @remarks
|
|
78
|
-
* This method unwraps a previously wrapped cryptographic key using the AES Key Wrap algorithm.
|
|
79
|
-
* The wrapped key, provided as a byte array, is unwrapped using the decryption key specified in
|
|
80
|
-
* the parameters.
|
|
81
|
-
*
|
|
82
|
-
* This operation is useful for securely receiving keys transmitted over untrusted mediums. The
|
|
83
|
-
* method returns the unwrapped key as a JSON Web Key (JWK).
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```ts
|
|
87
|
-
* const aesKw = new AesKwAlgorithm();
|
|
88
|
-
* const wrappedKeyBytes = new Uint8Array([...]); // Byte array of a wrapped AES-256 GCM key
|
|
89
|
-
* const decryptionKey = { ... }; // A Jwk object representing the AES unwrapping key
|
|
90
|
-
* const unwrappedKey = await aesKw.unwrapKey({
|
|
91
|
-
* wrappedKeyBytes,
|
|
92
|
-
* wrappedKeyAlgorithm: 'A256GCM',
|
|
93
|
-
* decryptionKey
|
|
94
|
-
* });
|
|
95
|
-
* ```
|
|
96
|
-
*
|
|
97
|
-
* @param params - The parameters for the key unwrapping operation.
|
|
98
|
-
*
|
|
99
|
-
* @returns A Promise that resolves to the unwrapped key in JWK format.
|
|
100
|
-
*/
|
|
101
|
-
unwrapKey(params) {
|
|
102
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
const unwrappedKey = yield AesKw.unwrapKey(params);
|
|
104
|
-
return unwrappedKey;
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Encrypts a given key using the AES Key Wrap algorithm.
|
|
109
|
-
*
|
|
110
|
-
* @remarks
|
|
111
|
-
* This method wraps a given cryptographic key using the AES Key Wrap algorithm. The private key
|
|
112
|
-
* to be wrapped is provided in the form of a JSON Web Key (JWK).
|
|
113
|
-
*
|
|
114
|
-
* This operation is useful for securely transmitting keys over untrusted mediums. The method
|
|
115
|
-
* returns the wrapped key as a byte array.
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```ts
|
|
119
|
-
* const aesKw = new AesKwAlgorithm();
|
|
120
|
-
* const unwrappedKey = { ... }; // A Jwk object representing the key to be wrapped
|
|
121
|
-
* const encryptionKey = { ... }; // A Jwk object representing the AES wrapping key
|
|
122
|
-
* const wrappedKeyBytes = await aesKw.wrapKey({ unwrappedKey, encryptionKey });
|
|
123
|
-
* ```
|
|
124
|
-
*
|
|
125
|
-
* @param params - The parameters for the key wrapping operation.
|
|
126
|
-
*
|
|
127
|
-
* @returns A Promise that resolves to the wrapped key as a Uint8Array.
|
|
128
|
-
*/
|
|
129
|
-
wrapKey(params) {
|
|
130
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
const wrappedKeyBytes = AesKw.wrapKey(params);
|
|
132
|
-
return wrappedKeyBytes;
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
//# sourceMappingURL=aes-kw.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aes-kw.js","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/algorithms/aes-kw.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAgBvD;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAe,SAAQ,eAAe;IAKpC,iBAAiB;6DAAC,EAAE,eAAe,EACS;YAEvD,mCAAmC;YACnC,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,iBAAiB,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC;YAEtE,kDAAkD;YAClD,UAAU,CAAC,GAAG,GAAG,EAAE,EAAE,E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