@enbox/agent 0.1.2 → 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 +13 -15
- 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,120 +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 { concatenateUrl } from './utils.js';
|
|
11
|
-
import { Convert } from '@enbox/common';
|
|
12
|
-
import { CryptoUtils, Sha256 } from '@enbox/crypto';
|
|
13
|
-
/**
|
|
14
|
-
* A client for registering tenants with a DWN.
|
|
15
|
-
*/
|
|
16
|
-
export class DwnRegistrar {
|
|
17
|
-
/**
|
|
18
|
-
* Registers a new tenant with the given DWN.
|
|
19
|
-
* NOTE: Assumes the user has already accepted the terms of service.
|
|
20
|
-
* NOTE: Currently the DWN Server from `dwn-server` does not require user signature.
|
|
21
|
-
* TODO: bring in types from `dwn-server`.
|
|
22
|
-
*/
|
|
23
|
-
static registerTenant(dwnEndpoint, did) {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
const registrationEndpoint = concatenateUrl(dwnEndpoint, 'registration');
|
|
26
|
-
const termsOfUseEndpoint = concatenateUrl(registrationEndpoint, 'terms-of-service');
|
|
27
|
-
const proofOfWorkEndpoint = concatenateUrl(registrationEndpoint, 'proof-of-work');
|
|
28
|
-
// fetch the terms-of-service
|
|
29
|
-
const termsOfServiceGetResponse = yield fetch(termsOfUseEndpoint, {
|
|
30
|
-
method: 'GET',
|
|
31
|
-
});
|
|
32
|
-
if (termsOfServiceGetResponse.status !== 200) {
|
|
33
|
-
const statusCode = termsOfServiceGetResponse.status;
|
|
34
|
-
const statusText = termsOfServiceGetResponse.statusText;
|
|
35
|
-
const errorText = yield termsOfServiceGetResponse.text();
|
|
36
|
-
throw new Error(`Failed fetching terms-of-service: ${statusCode} ${statusText}: ${errorText}`);
|
|
37
|
-
}
|
|
38
|
-
const termsOfServiceFetched = yield termsOfServiceGetResponse.text();
|
|
39
|
-
// fetch the proof-of-work challenge
|
|
40
|
-
const proofOfWorkChallengeGetResponse = yield fetch(proofOfWorkEndpoint, {
|
|
41
|
-
method: 'GET',
|
|
42
|
-
});
|
|
43
|
-
const { challengeNonce, maximumAllowedHashValue } = yield proofOfWorkChallengeGetResponse.json();
|
|
44
|
-
// create registration data based on the hash of the terms-of-service and the DID
|
|
45
|
-
const registrationData = {
|
|
46
|
-
did,
|
|
47
|
-
termsOfServiceHash: yield DwnRegistrar.hashAsHexString(termsOfServiceFetched),
|
|
48
|
-
};
|
|
49
|
-
// compute the proof-of-work response nonce based on the the proof-of-work challenge and the registration data.
|
|
50
|
-
const responseNonce = yield DwnRegistrar.findQualifiedResponseNonce({
|
|
51
|
-
challengeNonce,
|
|
52
|
-
maximumAllowedHashValue,
|
|
53
|
-
requestData: JSON.stringify(registrationData),
|
|
54
|
-
});
|
|
55
|
-
// send the registration request to the server
|
|
56
|
-
const registrationRequest = {
|
|
57
|
-
registrationData,
|
|
58
|
-
proofOfWork: {
|
|
59
|
-
challengeNonce,
|
|
60
|
-
responseNonce,
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
const registrationResponse = yield fetch(registrationEndpoint, {
|
|
64
|
-
method: 'POST',
|
|
65
|
-
headers: { 'Content-Type': 'application/json' },
|
|
66
|
-
body: JSON.stringify(registrationRequest),
|
|
67
|
-
});
|
|
68
|
-
if (registrationResponse.status !== 200) {
|
|
69
|
-
const statusCode = registrationResponse.status;
|
|
70
|
-
const statusText = registrationResponse.statusText;
|
|
71
|
-
const errorText = yield registrationResponse.text();
|
|
72
|
-
throw new Error(`Registration failed: ${statusCode} ${statusText}: ${errorText}`);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Computes the SHA-256 hash of the given array of strings.
|
|
78
|
-
*/
|
|
79
|
-
static hashAsHexString(input) {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
const hashAsBytes = yield Sha256.digest({ data: Convert.string(input).toUint8Array() });
|
|
82
|
-
const hashAsHex = Convert.uint8Array(hashAsBytes).toHex();
|
|
83
|
-
return hashAsHex;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Finds a response nonce that qualifies the difficulty requirement for the given proof-of-work challenge and request data.
|
|
88
|
-
*/
|
|
89
|
-
static findQualifiedResponseNonce(input) {
|
|
90
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
const startTime = Date.now();
|
|
92
|
-
const { maximumAllowedHashValue, challengeNonce, requestData } = input;
|
|
93
|
-
const maximumAllowedHashValueAsBigInt = BigInt(`0x${maximumAllowedHashValue}`);
|
|
94
|
-
let iterations = 1;
|
|
95
|
-
let responseNonce;
|
|
96
|
-
let qualifiedSolutionNonceFound = false;
|
|
97
|
-
do {
|
|
98
|
-
responseNonce = yield this.generateNonce();
|
|
99
|
-
const computedHash = yield DwnRegistrar.hashAsHexString(challengeNonce + responseNonce + requestData);
|
|
100
|
-
const computedHashAsBigInt = BigInt(`0x${computedHash}`);
|
|
101
|
-
qualifiedSolutionNonceFound = computedHashAsBigInt <= maximumAllowedHashValueAsBigInt;
|
|
102
|
-
iterations++;
|
|
103
|
-
} while (!qualifiedSolutionNonceFound);
|
|
104
|
-
// Log final/successful iteration.
|
|
105
|
-
console.log(`iterations: ${iterations}, time lapsed: ${Date.now() - startTime} ms`);
|
|
106
|
-
return responseNonce;
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Generates 32 random bytes expressed as a HEX string.
|
|
111
|
-
*/
|
|
112
|
-
static generateNonce() {
|
|
113
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
const randomBytes = CryptoUtils.randomBytes(32);
|
|
115
|
-
const hexString = Convert.uint8Array(randomBytes).toHex().toUpperCase();
|
|
116
|
-
return hexString;
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
//# sourceMappingURL=dwn-registrar.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dwn-registrar.js","sourceRoot":"","sources":["../../src/dwn-registrar.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CA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(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 ms from 'ms';
|
|
11
|
-
import { TtlCache } from '@enbox/common';
|
|
12
|
-
export class DwnServerInfoCacheMemory {
|
|
13
|
-
constructor({ ttl = '15m' } = {}) {
|
|
14
|
-
this.cache = new TtlCache({ ttl: ms(ttl) });
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Retrieves a DWN ServerInfo entry from the cache.
|
|
18
|
-
*
|
|
19
|
-
* If the cached item has exceeded its TTL, it's scheduled for deletion and undefined is returned.
|
|
20
|
-
*
|
|
21
|
-
* @param dwnUrl - The DWN URL endpoint string used as the key for getting the entry.
|
|
22
|
-
* @returns The cached DWN ServerInfo entry or undefined if not found or expired.
|
|
23
|
-
*/
|
|
24
|
-
get(dwnUrl) {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
return this.cache.get(dwnUrl);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Stores a DWN ServerInfo entry in the cache with a TTL.
|
|
31
|
-
*
|
|
32
|
-
* @param dwnUrl - The DWN URL endpoint string used as the key for storing the entry.
|
|
33
|
-
* @param value - The DWN ServerInfo entry to be cached.
|
|
34
|
-
* @returns A promise that resolves when the operation is complete.
|
|
35
|
-
*/
|
|
36
|
-
set(dwnUrl, value) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
this.cache.set(dwnUrl, value);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Deletes a DWN ServerInfo entry from the cache.
|
|
43
|
-
*
|
|
44
|
-
* @param dwnUrl - The DWN URL endpoint string used as the key for deletion.
|
|
45
|
-
* @returns A promise that resolves when the operation is complete.
|
|
46
|
-
*/
|
|
47
|
-
delete(dwnUrl) {
|
|
48
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
this.cache.delete(dwnUrl);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Clears all entries from the cache.
|
|
54
|
-
*
|
|
55
|
-
* @returns A promise that resolves when the operation is complete.
|
|
56
|
-
*/
|
|
57
|
-
clear() {
|
|
58
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
this.cache.clear();
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* This method is a no-op but exists to be consistent with other DWN ServerInfo Cache
|
|
64
|
-
* implementations.
|
|
65
|
-
*
|
|
66
|
-
* @returns A promise that resolves immediately.
|
|
67
|
-
*/
|
|
68
|
-
close() {
|
|
69
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
// No-op since there is no underlying store to close.
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=dwn-server-info-cache-memory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dwn-server-info-cache-memory.js","sourceRoot":"","sources":["../../../../src/prototyping/clients/dwn-server-info-cache-memory.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAkBzC,MAAM,OAAO,wBAAwB;IAGnC,YAAY,EAAE,GAAG,GAAG,KAAK,KAAoC,EAAE;QAC7D,IAAI,CAAC,KAAK,GAAG,IAAI,QAAQ,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;;;OAOG;IACU,GAAG,CAAC,MAAc;;YAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;KAAA;IAED;;;;;;OAMG;IACU,GAAG,CAAC,MAAc,EAAE,KAAiB;;YAChD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAChC,CAAC;KAAA;IAED;;;;;OAKG;IACU,MAAM,CAAC,MAAc;;YAChC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;KAAA;IAED;;;;OAIG;IACU,KAAK;;YAChB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;KAAA;IAED;;;;;OAKG;IACU,KAAK;;YAChB,qDAAqD;QACvD,CAAC;KAAA;CACF"}
|
|
@@ -1,112 +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 { DataStream } from '@enbox/dwn-sdk-js';
|
|
12
|
-
import { DwnServerInfoCacheMemory } from './dwn-server-info-cache-memory.js';
|
|
13
|
-
import { createJsonRpcRequest, parseJson } from './json-rpc.js';
|
|
14
|
-
/**
|
|
15
|
-
* HTTP client that can be used to communicate with Dwn Servers
|
|
16
|
-
*/
|
|
17
|
-
export class HttpDwnRpcClient {
|
|
18
|
-
constructor(serverInfoCache) {
|
|
19
|
-
this.serverInfoCache = serverInfoCache !== null && serverInfoCache !== void 0 ? serverInfoCache : new DwnServerInfoCacheMemory();
|
|
20
|
-
}
|
|
21
|
-
get transportProtocols() { return ['http:', 'https:']; }
|
|
22
|
-
sendDwnRequest(request) {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
const requestId = CryptoUtils.randomUuid();
|
|
25
|
-
const jsonRpcRequest = createJsonRpcRequest(requestId, 'dwn.processMessage', {
|
|
26
|
-
target: request.targetDid,
|
|
27
|
-
message: request.message
|
|
28
|
-
});
|
|
29
|
-
const requestHeaders = {
|
|
30
|
-
'dwn-request': JSON.stringify(jsonRpcRequest)
|
|
31
|
-
};
|
|
32
|
-
const fetchOpts = {
|
|
33
|
-
method: 'POST',
|
|
34
|
-
headers: requestHeaders,
|
|
35
|
-
};
|
|
36
|
-
if (request.data) {
|
|
37
|
-
requestHeaders['content-type'] = 'application/octet-stream';
|
|
38
|
-
fetchOpts.body = request.data;
|
|
39
|
-
}
|
|
40
|
-
const resp = yield fetch(request.dwnUrl, fetchOpts);
|
|
41
|
-
let dwnRpcResponse;
|
|
42
|
-
// When the server streams record data back, the JSON-RPC envelope is in the
|
|
43
|
-
// `dwn-response` header and the body is the raw data stream. Otherwise the
|
|
44
|
-
// entire JSON-RPC response is the body.
|
|
45
|
-
const hasDataStream = resp.headers.has('dwn-response');
|
|
46
|
-
if (hasDataStream) {
|
|
47
|
-
const jsonRpcResponse = parseJson(resp.headers.get('dwn-response'));
|
|
48
|
-
if (jsonRpcResponse == null) {
|
|
49
|
-
throw new Error(`failed to parse json rpc response. dwn url: ${request.dwnUrl}`);
|
|
50
|
-
}
|
|
51
|
-
dwnRpcResponse = jsonRpcResponse;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
const responseBody = yield resp.text();
|
|
55
|
-
dwnRpcResponse = JSON.parse(responseBody);
|
|
56
|
-
}
|
|
57
|
-
if (dwnRpcResponse.error) {
|
|
58
|
-
const { code, message } = dwnRpcResponse.error;
|
|
59
|
-
throw new Error(`(${code}) - ${message}`);
|
|
60
|
-
}
|
|
61
|
-
// Materialise the response body before attaching to the reply.
|
|
62
|
-
// Bun (<=1.3.9) has a bug where resp.body.getReader() can intermittently
|
|
63
|
-
// return undefined, crashing DataStream.toBytes() in its finally block.
|
|
64
|
-
// Buffering via arrayBuffer() is a safe workaround.
|
|
65
|
-
// TODO: https://github.com/enboxorg/enbox/issues/90 — remove once Bun ships fix
|
|
66
|
-
const { reply } = dwnRpcResponse.result;
|
|
67
|
-
if (hasDataStream) {
|
|
68
|
-
const bodyBytes = new Uint8Array(yield resp.arrayBuffer());
|
|
69
|
-
const dataStream = DataStream.fromBytes(bodyBytes);
|
|
70
|
-
if (reply.record) {
|
|
71
|
-
reply.record.data = dataStream;
|
|
72
|
-
}
|
|
73
|
-
else if (reply.entry) {
|
|
74
|
-
reply.entry.data = dataStream;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return reply;
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
getServerInfo(dwnUrl) {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
const serverInfo = yield this.serverInfoCache.get(dwnUrl);
|
|
83
|
-
if (serverInfo) {
|
|
84
|
-
return serverInfo;
|
|
85
|
-
}
|
|
86
|
-
const url = new URL(dwnUrl);
|
|
87
|
-
// add `/info` to the dwn server url path
|
|
88
|
-
url.pathname.endsWith('/') ? url.pathname += 'info' : url.pathname += '/info';
|
|
89
|
-
try {
|
|
90
|
-
const response = yield fetch(url.toString());
|
|
91
|
-
if (response.ok) {
|
|
92
|
-
const results = yield response.json();
|
|
93
|
-
// explicitly return and cache only the desired properties.
|
|
94
|
-
const serverInfo = {
|
|
95
|
-
registrationRequirements: results.registrationRequirements,
|
|
96
|
-
maxFileSize: results.maxFileSize,
|
|
97
|
-
webSocketSupport: results.webSocketSupport,
|
|
98
|
-
};
|
|
99
|
-
this.serverInfoCache.set(dwnUrl, serverInfo);
|
|
100
|
-
return serverInfo;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
throw new Error(`HTTP (${response.status}) - ${response.statusText}`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
throw new Error(`Error encountered while processing response from ${url.toString()}: ${error.message}`);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
//# sourceMappingURL=http-dwn-rpc-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-dwn-rpc-client.js","sourceRoot":"","sources":["../../../../src/prototyping/clients/http-dwn-rpc-client.ts"],"names":[],"mappings":";;;;;;;;;AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEhE;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAE3B,YAAY,eAAoC;QAC9C,IAAI,CAAC,eAAe,GAAG,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,IAAI,wBAAwB,EAAE,CAAC;IAC3E,CAAC;IAED,IAAI,kBAAkB,KAAe,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE5D,cAAc,CAAC,OAAsB;;YACzC,MAAM,SAAS,GAAG,WAAW,CAAC,UAAU,EAAE,CAAC;YAC3C,MAAM,cAAc,GAAG,oBAAoB,CAAC,SAAS,EAAE,oBAAoB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,CAAC,EAAE,EAAE,CAAC;oBAChB,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAgB,CAAC;oBAEpD,2DAA2D;oBAC3D,MAAM,UAAU,GAAG;wBACjB,wBAAwB,EAAG,OAAO,CAAC,wBAAwB;wBAC3D,WAAW,EAAgB,OAAO,CAAC,WAAW;wBAC9C,gBAAgB,EAAW,OAAO,CAAC,gBAAgB;qBACpD,CAAC;oBACF,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;oBAE7C,OAAO,UAAU,CAAC;gBACpB,CAAC;qBAAM,CAAC;oBACN,MAAM,IAAI,KAAK,CAAC,SAAS,QAAQ,CAAC,MAAM,OAAO,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;gBACxE,CAAC;YACH,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,oDAAoD,GAAG,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YAC1G,CAAC;QACH,CAAC;KAAA;CACF"}
|
|
@@ -1,167 +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 { createJsonRpcSubscriptionRequest, parseJson } from './json-rpc.js';
|
|
12
|
-
/**
|
|
13
|
-
* Converts WebSocket message data to a string.
|
|
14
|
-
* Bun's native WebSocket delivers `event.data` as an `ArrayBuffer`,
|
|
15
|
-
* whereas Node.js `ws` delivers it as a `string`.
|
|
16
|
-
*/
|
|
17
|
-
function toText(data) {
|
|
18
|
-
if (typeof data === 'string') {
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
if (data instanceof ArrayBuffer) {
|
|
22
|
-
return new TextDecoder().decode(data);
|
|
23
|
-
}
|
|
24
|
-
// Buffer / Uint8Array fallback
|
|
25
|
-
if (data instanceof Uint8Array) {
|
|
26
|
-
return new TextDecoder().decode(data);
|
|
27
|
-
}
|
|
28
|
-
return String(data);
|
|
29
|
-
}
|
|
30
|
-
// These were arbitrarily chosen, but can be modified via connect options
|
|
31
|
-
const CONNECT_TIMEOUT = 3000;
|
|
32
|
-
const RESPONSE_TIMEOUT = 30000;
|
|
33
|
-
/**
|
|
34
|
-
* JSON RPC Socket Client for WebSocket request/response and long-running subscriptions.
|
|
35
|
-
*
|
|
36
|
-
* NOTE: This is temporarily copied over from https://github.com/enboxorg/enbox/blob/main/packages/dwn-server/src/json-rpc-socket.ts
|
|
37
|
-
* This was done in order to avoid taking a dependency on the `dwn-server`, until a future time when there will be a `clients` package.
|
|
38
|
-
*/
|
|
39
|
-
export class JsonRpcSocket {
|
|
40
|
-
constructor(socket, responseTimeout) {
|
|
41
|
-
this.socket = socket;
|
|
42
|
-
this.responseTimeout = responseTimeout;
|
|
43
|
-
this.messageHandlers = new Map();
|
|
44
|
-
}
|
|
45
|
-
static connect(url_1) {
|
|
46
|
-
return __awaiter(this, arguments, void 0, function* (url, options = {}) {
|
|
47
|
-
const { connectTimeout = CONNECT_TIMEOUT, responseTimeout = RESPONSE_TIMEOUT, onclose, onerror } = options;
|
|
48
|
-
const socket = new WebSocket(url);
|
|
49
|
-
if (!onclose) {
|
|
50
|
-
socket.onclose = () => {
|
|
51
|
-
console.info(`JSON RPC Socket close ${url}`);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
socket.onclose = onclose;
|
|
56
|
-
}
|
|
57
|
-
if (!onerror) {
|
|
58
|
-
socket.onerror = (error) => {
|
|
59
|
-
console.error(`JSON RPC Socket error ${url}`, error);
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
socket.onerror = onerror;
|
|
64
|
-
}
|
|
65
|
-
return new Promise((resolve, reject) => {
|
|
66
|
-
socket.addEventListener('open', () => {
|
|
67
|
-
const jsonRpcSocket = new JsonRpcSocket(socket, responseTimeout);
|
|
68
|
-
socket.addEventListener('message', (event) => {
|
|
69
|
-
const jsonRpcResponse = parseJson(toText(event.data));
|
|
70
|
-
const handler = jsonRpcSocket.messageHandlers.get(jsonRpcResponse.id);
|
|
71
|
-
if (handler) {
|
|
72
|
-
handler(event);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
resolve(jsonRpcSocket);
|
|
76
|
-
});
|
|
77
|
-
socket.addEventListener('error', (error) => {
|
|
78
|
-
reject(error);
|
|
79
|
-
});
|
|
80
|
-
setTimeout(() => reject(new Error('connect timed out')), connectTimeout);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
close() {
|
|
85
|
-
this.socket.close();
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Sends a JSON-RPC request through the socket and waits for a single response.
|
|
89
|
-
*/
|
|
90
|
-
request(request) {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
return new Promise((resolve, reject) => {
|
|
93
|
-
var _a;
|
|
94
|
-
(_a = request.id) !== null && _a !== void 0 ? _a : (request.id = CryptoUtils.randomUuid());
|
|
95
|
-
const handleResponse = (event) => {
|
|
96
|
-
const jsonRpsResponse = parseJson(toText(event.data));
|
|
97
|
-
if (jsonRpsResponse.id === request.id) {
|
|
98
|
-
// if the incoming response id matches the request id, we will remove the listener and resolve the response
|
|
99
|
-
this.messageHandlers.delete(request.id);
|
|
100
|
-
return resolve(jsonRpsResponse);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
// add the listener to the map of message handlers
|
|
104
|
-
this.messageHandlers.set(request.id, handleResponse);
|
|
105
|
-
this.send(request);
|
|
106
|
-
// reject this promise if we don't receive any response back within the timeout period
|
|
107
|
-
setTimeout(() => {
|
|
108
|
-
this.messageHandlers.delete(request.id);
|
|
109
|
-
reject(new Error('request timed out'));
|
|
110
|
-
}, this.responseTimeout);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Sends a JSON-RPC request through the socket and keeps a listener open to read associated responses as they arrive.
|
|
116
|
-
* Returns a close method to clean up the listener.
|
|
117
|
-
*/
|
|
118
|
-
subscribe(request, listener) {
|
|
119
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
if (!request.method.startsWith('rpc.subscribe.')) {
|
|
121
|
-
throw new Error('subscribe rpc requests must include the `rpc.subscribe` prefix');
|
|
122
|
-
}
|
|
123
|
-
if (!request.subscription) {
|
|
124
|
-
throw new Error('subscribe rpc requests must include subscribe options');
|
|
125
|
-
}
|
|
126
|
-
const subscriptionId = request.subscription.id;
|
|
127
|
-
const socketEventListener = (event) => {
|
|
128
|
-
const jsonRpcResponse = parseJson(toText(event.data));
|
|
129
|
-
if (jsonRpcResponse.id === subscriptionId) {
|
|
130
|
-
if (jsonRpcResponse.error !== undefined) {
|
|
131
|
-
// remove the event listener upon receipt of a JSON RPC Error.
|
|
132
|
-
this.messageHandlers.delete(subscriptionId);
|
|
133
|
-
this.closeSubscription(subscriptionId);
|
|
134
|
-
}
|
|
135
|
-
listener(jsonRpcResponse);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
this.messageHandlers.set(subscriptionId, socketEventListener);
|
|
139
|
-
const response = yield this.request(request);
|
|
140
|
-
if (response.error) {
|
|
141
|
-
this.messageHandlers.delete(subscriptionId);
|
|
142
|
-
return { response };
|
|
143
|
-
}
|
|
144
|
-
// clean up listener and create a `rpc.subscribe.close` message to use when closing this JSON RPC subscription
|
|
145
|
-
const close = () => __awaiter(this, void 0, void 0, function* () {
|
|
146
|
-
this.messageHandlers.delete(subscriptionId);
|
|
147
|
-
yield this.closeSubscription(subscriptionId);
|
|
148
|
-
});
|
|
149
|
-
return {
|
|
150
|
-
response,
|
|
151
|
-
close
|
|
152
|
-
};
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
closeSubscription(id) {
|
|
156
|
-
const requestId = CryptoUtils.randomUuid();
|
|
157
|
-
const request = createJsonRpcSubscriptionRequest(requestId, 'close', id, {});
|
|
158
|
-
return this.request(request);
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Sends a JSON-RPC request through the socket. You must subscribe to a message listener separately to capture the response.
|
|
162
|
-
*/
|
|
163
|
-
send(request) {
|
|
164
|
-
this.socket.send(JSON.stringify(request));
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
//# sourceMappingURL=json-rpc-socket.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc-socket.js","sourceRoot":"","sources":["../../../../src/prototyping/clients/json-rpc-socket.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gCAAgC,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE5E;;;;GAIG;AACH,SAAS,MAAM,CAAC,IAAa;IAC3B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,IAAI,YAAY,WAAW,EAAE,CAAC;QAChC,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IACD,+BAA+B;IAC/B,IAAI,IAAI,YAAY,UAAU,EAAE,CAAC;QAC/B,OAAO,IAAI,WA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
|
-
export var JsonRpcErrorCodes;
|
|
2
|
-
(function (JsonRpcErrorCodes) {
|
|
3
|
-
// JSON-RPC 2.0 pre-defined errors
|
|
4
|
-
JsonRpcErrorCodes[JsonRpcErrorCodes["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
5
|
-
JsonRpcErrorCodes[JsonRpcErrorCodes["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
6
|
-
JsonRpcErrorCodes[JsonRpcErrorCodes["InvalidParams"] = -32602] = "InvalidParams";
|
|
7
|
-
JsonRpcErrorCodes[JsonRpcErrorCodes["InternalError"] = -32603] = "InternalError";
|
|
8
|
-
JsonRpcErrorCodes[JsonRpcErrorCodes["ParseError"] = -32700] = "ParseError";
|
|
9
|
-
JsonRpcErrorCodes[JsonRpcErrorCodes["TransportError"] = -32300] = "TransportError";
|
|
10
|
-
// App defined errors
|
|
11
|
-
JsonRpcErrorCodes[JsonRpcErrorCodes["BadRequest"] = -50400] = "BadRequest";
|
|
12
|
-
JsonRpcErrorCodes[JsonRpcErrorCodes["Unauthorized"] = -50401] = "Unauthorized";
|
|
13
|
-
JsonRpcErrorCodes[JsonRpcErrorCodes["Forbidden"] = -50403] = "Forbidden";
|
|
14
|
-
JsonRpcErrorCodes[JsonRpcErrorCodes["Conflict"] = -50409] = "Conflict";
|
|
15
|
-
})(JsonRpcErrorCodes || (JsonRpcErrorCodes = {}));
|
|
16
|
-
export const createJsonRpcErrorResponse = (id, code, message, data) => {
|
|
17
|
-
const error = { code, message, data };
|
|
18
|
-
return {
|
|
19
|
-
jsonrpc: '2.0',
|
|
20
|
-
id,
|
|
21
|
-
error,
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export const createJsonRpcRequest = (id, method, params) => {
|
|
25
|
-
return {
|
|
26
|
-
jsonrpc: '2.0',
|
|
27
|
-
id,
|
|
28
|
-
method,
|
|
29
|
-
params,
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
export const createJsonRpcSubscriptionRequest = (id, method, subscriptionId, params) => {
|
|
33
|
-
return {
|
|
34
|
-
jsonrpc: '2.0',
|
|
35
|
-
id,
|
|
36
|
-
method: `rpc.subscribe.${method}`,
|
|
37
|
-
params,
|
|
38
|
-
subscription: {
|
|
39
|
-
id: subscriptionId,
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
export const createJsonRpcSuccessResponse = (id, result) => {
|
|
44
|
-
return {
|
|
45
|
-
jsonrpc: '2.0',
|
|
46
|
-
id,
|
|
47
|
-
result,
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
export function parseJson(text) {
|
|
51
|
-
try {
|
|
52
|
-
return JSON.parse(text);
|
|
53
|
-
}
|
|
54
|
-
catch (_a) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=json-rpc.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc.js","sourceRoot":"","sources":["../../../../src/prototyping/clients/json-rpc.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAN,IAAY,iBAcX;AAdD,WAAY,iBAAiB;IAC3B,kCAAkC;IAClC,kFAAuB,CAAA;IACvB,kFAAuB,CAAA;IACvB,gFAAsB,CAAA;IACtB,gFAAsB,CAAA;IACtB,0EAAmB,CAAA;IACnB,kFAAuB,CAAA;IAEvB,qBAAqB;IACrB,0EAAmB,CAAA;IACnB,8EAAqB,CAAA;IACrB,wEAAkB,CAAA;IAClB,sEAAiB,CAAA;AACnB,CAAC,EAdW,iBAAiB,KAAjB,iBAAiB,QAc5B;AAkBD,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,EAAa,EACb,IAAuB,EACvB,OAAe,EACf,IAAU,EACY,EAAE;IACxB,MAAM,KAAK,GAAiB,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACpD,OAAO;QACL,OAAO,EAAE,KAAK;QACd,EAAE;QACF,KAAK;KACN,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,EAAa,EACb,MAAc,EACd,MAAsB,EACN,EAAE;IAClB,OAAO;QACL,OAAO,EAAE,KAAK;QACd,EAAE;QACF,MAAM;QACN,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAC9C,EAAa,EACb,MAAc,EACd,cAAyB,EACzB,MAAY,EACI,EAAE;IAClB,OAAO;QACL,OAAO,EAAQ,KAAK;QACpB,EAAE;QACF,MAAM,EAAS,iBAAiB,MAAM,EAAE;QACxC,MAAM;QACN,YAAY,EAAG;YACb,EAAE,EAAE,cAAc;SACnB;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,EAAa,EACb,MAAW,EACa,EAAE;IAC1B,OAAO;QACL,OAAO,EAAE,KAAK;QACd,EAAE;QACF,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server-info-types.js","sourceRoot":"","sources":["../../../../src/prototyping/clients/server-info-types.ts"],"names":[],"mappings":""}
|