@enbox/agent 0.4.0 → 0.5.0
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 +8 -8
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/enbox-connect-protocol.js +0 -20
- package/dist/esm/enbox-connect-protocol.js.map +1 -1
- package/dist/esm/enbox-user-agent.js +1 -7
- package/dist/esm/enbox-user-agent.js.map +1 -1
- package/dist/esm/hd-identity-vault.js +11 -0
- package/dist/esm/hd-identity-vault.js.map +1 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/test-harness.js +2 -3
- package/dist/esm/test-harness.js.map +1 -1
- package/dist/esm/types/dwn.js.map +1 -1
- package/dist/types/enbox-connect-protocol.d.ts +13 -27
- package/dist/types/enbox-connect-protocol.d.ts.map +1 -1
- package/dist/types/enbox-user-agent.d.ts +3 -7
- package/dist/types/enbox-user-agent.d.ts.map +1 -1
- package/dist/types/hd-identity-vault.d.ts +7 -0
- package/dist/types/hd-identity-vault.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/test-harness.d.ts.map +1 -1
- package/dist/types/types/agent.d.ts +2 -7
- package/dist/types/types/agent.d.ts.map +1 -1
- package/dist/types/types/dwn.d.ts +0 -10
- package/dist/types/types/dwn.d.ts.map +1 -1
- package/dist/types/types/sync.d.ts +6 -0
- package/dist/types/types/sync.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/enbox-connect-protocol.ts +14 -39
- package/src/enbox-user-agent.ts +4 -14
- package/src/hd-identity-vault.ts +21 -0
- package/src/index.ts +0 -2
- package/src/test-harness.ts +2 -3
- package/src/types/agent.ts +3 -14
- package/src/types/dwn.ts +1 -13
- package/src/types/sync.ts +7 -0
- package/dist/esm/connect.js +0 -176
- package/dist/esm/connect.js.map +0 -1
- package/dist/esm/sync-api.js +0 -64
- package/dist/esm/sync-api.js.map +0 -1
- package/dist/types/connect.d.ts +0 -84
- package/dist/types/connect.d.ts.map +0 -1
- package/dist/types/sync-api.d.ts +0 -40
- package/dist/types/sync-api.d.ts.map +0 -1
- package/src/connect.ts +0 -276
- package/src/sync-api.ts +0 -75
package/dist/types/connect.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type { EnboxConnectResponse } from './enbox-connect-protocol.js';
|
|
2
|
-
import type { DwnPermissionScope, DwnProtocolDefinition } from './index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Initiates the wallet connect process. Used when a client wants to obtain
|
|
5
|
-
* a did from a provider.
|
|
6
|
-
*/
|
|
7
|
-
declare function initClient({ displayName, connectServerUrl, walletUri, permissionRequests, onWalletUriReady, validatePin, }: WalletConnectOptions): Promise<{
|
|
8
|
-
delegateGrants: EnboxConnectResponse['delegateGrants'];
|
|
9
|
-
delegatePortableDid: EnboxConnectResponse['delegatePortableDid'];
|
|
10
|
-
connectedDid: string;
|
|
11
|
-
} | undefined>;
|
|
12
|
-
/**
|
|
13
|
-
* Options for initiating a wallet connect flow (remote, relay-mediated).
|
|
14
|
-
*/
|
|
15
|
-
export type WalletConnectOptions = {
|
|
16
|
-
/** The user-friendly name of the app, displayed in the wallet consent UI. */
|
|
17
|
-
displayName: string;
|
|
18
|
-
/** The URL of the connect server which relays messages between the app and wallet. */
|
|
19
|
-
connectServerUrl: string;
|
|
20
|
-
/**
|
|
21
|
-
* The URI of the wallet app. Query params (`request_uri`, `encryption_key`)
|
|
22
|
-
* are appended and passed to `onWalletUriReady`.
|
|
23
|
-
* @example `enbox://connect` or `http://localhost:3000/`
|
|
24
|
-
*/
|
|
25
|
-
walletUri: string;
|
|
26
|
-
/**
|
|
27
|
-
* The protocols of permissions requested, along with the definition and
|
|
28
|
-
* permission scopes for each protocol. The key is the protocol URL and
|
|
29
|
-
* the value is an object with the protocol definition and the permission scopes.
|
|
30
|
-
*/
|
|
31
|
-
permissionRequests: ConnectPermissionRequest[];
|
|
32
|
-
/**
|
|
33
|
-
* Called with the wallet URI including query params (`request_uri`, `encryption_key`).
|
|
34
|
-
* The app should render this as a QR code or use it as a deep link.
|
|
35
|
-
*
|
|
36
|
-
* @param uri - The wallet URI with connect payload.
|
|
37
|
-
*/
|
|
38
|
-
onWalletUriReady: (uri: string) => void;
|
|
39
|
-
/**
|
|
40
|
-
* Called to collect the PIN from the user. The PIN is used as AAD
|
|
41
|
-
* when decrypting the connect response from the relay.
|
|
42
|
-
*
|
|
43
|
-
* @returns A promise that resolves to the PIN as a string.
|
|
44
|
-
*/
|
|
45
|
-
validatePin: () => Promise<string>;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* The protocols of permissions requested, along with the definition and permission scopes for each protocol.
|
|
49
|
-
*/
|
|
50
|
-
export type ConnectPermissionRequest = {
|
|
51
|
-
/**
|
|
52
|
-
* The definition of the protocol the permissions are being requested for.
|
|
53
|
-
* In the event that the protocol is not already installed, the wallet will install this given protocol definition.
|
|
54
|
-
*/
|
|
55
|
-
protocolDefinition: DwnProtocolDefinition;
|
|
56
|
-
/** The scope of the permissions being requested for the given protocol */
|
|
57
|
-
permissionScopes: DwnPermissionScope[];
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Shorthand for the types of permissions that can be requested.
|
|
61
|
-
*/
|
|
62
|
-
export type Permission = 'write' | 'read' | 'delete' | 'query' | 'subscribe' | 'configure';
|
|
63
|
-
/**
|
|
64
|
-
* The options for creating a permission request for a given protocol.
|
|
65
|
-
*/
|
|
66
|
-
export type ProtocolPermissionOptions = {
|
|
67
|
-
/** The protocol definition for the protocol being requested */
|
|
68
|
-
definition: DwnProtocolDefinition;
|
|
69
|
-
/** The permissions being requested for the protocol */
|
|
70
|
-
permissions: Permission[];
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Creates a set of Dwn Permission Scopes to request for a given protocol.
|
|
74
|
-
*
|
|
75
|
-
* If no permissions are provided, the default is to request all relevant record permissions (write, read, delete, query, subscribe).
|
|
76
|
-
* 'configure' is not included by default, as this gives the application a lot of control over the protocol.
|
|
77
|
-
*/
|
|
78
|
-
declare function createPermissionRequestForProtocol({ definition, permissions }: ProtocolPermissionOptions): ConnectPermissionRequest;
|
|
79
|
-
export declare const WalletConnect: {
|
|
80
|
-
initClient: typeof initClient;
|
|
81
|
-
createPermissionRequestForProtocol: typeof createPermissionRequestForProtocol;
|
|
82
|
-
};
|
|
83
|
-
export {};
|
|
84
|
-
//# sourceMappingURL=connect.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyB,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAC/F,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAS5E;;;GAGG;AACH,iBAAe,UAAU,CAAC,EACxB,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,GACZ,EAAE,oBAAoB,GAAG,OAAO,CAAC;IAChC,cAAc,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;IACvD,mBAAmB,EAAE,oBAAoB,CAAC,qBAAqB,CAAC,CAAC;IACjE,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,SAAS,CAAC,CAkGb;AAED;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,6EAA6E;IAC7E,WAAW,EAAE,MAAM,CAAC;IAEpB,sFAAsF;IACtF,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,kBAAkB,EAAE,wBAAwB,EAAE,CAAC;IAE/C;;;;;OAKG;IACH,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAExC;;;;;OAKG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CACpC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;OAGG;IACH,kBAAkB,EAAE,qBAAqB,CAAC;IAE1C,0EAA0E;IAC1E,gBAAgB,EAAE,kBAAkB,EAAE,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,WAAW,GAAG,WAAW,CAAC;AAE3F;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,+DAA+D;IAC/D,UAAU,EAAE,qBAAqB,CAAC;IAElC,uDAAuD;IACvD,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B,CAAC;AAEF;;;;;GAKG;AACH,iBAAS,kCAAkC,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,yBAAyB,GAAG,wBAAwB,CAsE5H;AAED,eAAO,MAAM,aAAa;;;CAAqD,CAAC"}
|
package/dist/types/sync-api.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { EnboxPlatformAgent } from './types/agent.js';
|
|
2
|
-
import type { StartSyncParams, SyncConnectivityState, SyncEngine, SyncIdentityOptions } from './types/sync.js';
|
|
3
|
-
export type SyncApiParams = {
|
|
4
|
-
agent?: EnboxPlatformAgent;
|
|
5
|
-
syncEngine: SyncEngine;
|
|
6
|
-
};
|
|
7
|
-
export declare class AgentSyncApi implements SyncEngine {
|
|
8
|
-
/**
|
|
9
|
-
* Holds the instance of a `EnboxPlatformAgent` that represents the current execution context for
|
|
10
|
-
* the `AgentSyncApi`. This agent is used to interact with other Enbox agent components. It's vital
|
|
11
|
-
* to ensure this instance is set to correctly contextualize operations within the broader Enbox
|
|
12
|
-
* Agent framework.
|
|
13
|
-
*/
|
|
14
|
-
private _agent?;
|
|
15
|
-
private _syncEngine;
|
|
16
|
-
constructor({ agent, syncEngine }: SyncApiParams);
|
|
17
|
-
/**
|
|
18
|
-
* Retrieves the `EnboxPlatformAgent` execution context.
|
|
19
|
-
*
|
|
20
|
-
* @returns The `EnboxPlatformAgent` instance that represents the current execution context.
|
|
21
|
-
* @throws Will throw an error if the `agent` instance property is undefined.
|
|
22
|
-
*/
|
|
23
|
-
get agent(): EnboxPlatformAgent;
|
|
24
|
-
set agent(agent: EnboxPlatformAgent);
|
|
25
|
-
get connectivityState(): SyncConnectivityState;
|
|
26
|
-
registerIdentity(params: {
|
|
27
|
-
did: string;
|
|
28
|
-
options?: SyncIdentityOptions;
|
|
29
|
-
}): Promise<void>;
|
|
30
|
-
unregisterIdentity(did: string): Promise<void>;
|
|
31
|
-
getIdentityOptions(did: string): Promise<SyncIdentityOptions | undefined>;
|
|
32
|
-
updateIdentityOptions(params: {
|
|
33
|
-
did: string;
|
|
34
|
-
options: SyncIdentityOptions;
|
|
35
|
-
}): Promise<void>;
|
|
36
|
-
sync(direction?: 'push' | 'pull'): Promise<void>;
|
|
37
|
-
startSync(params: StartSyncParams): Promise<void>;
|
|
38
|
-
stopSync(timeout?: number): Promise<void>;
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=sync-api.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync-api.d.ts","sourceRoot":"","sources":["../../src/sync-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE/G,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,qBAAa,YAAa,YAAW,UAAU;IAC7C;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,CAAqB;IAEpC,OAAO,CAAC,WAAW,CAAa;gBAEpB,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,aAAa;IAKhD;;;;;OAKG;IACH,IAAI,KAAK,IAAI,kBAAkB,CAM9B;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,kBAAkB,EAGlC;IAED,IAAI,iBAAiB,IAAI,qBAAqB,CAE7C;IAEY,gBAAgB,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,mBAAmB,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvF,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IAIzE,qBAAqB,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,mBAAmB,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjG,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhD,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGjD"}
|
package/src/connect.ts
DELETED
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import type { ConnectPushedResponse, EnboxConnectResponse } from './enbox-connect-protocol.js';
|
|
3
|
-
import type { DwnPermissionScope, DwnProtocolDefinition } from './index.js';
|
|
4
|
-
|
|
5
|
-
import { CryptoUtils } from '@enbox/crypto';
|
|
6
|
-
import { DidJwk } from '@enbox/dids';
|
|
7
|
-
import { EnboxConnectProtocol } from './enbox-connect-protocol.js';
|
|
8
|
-
import { pollWithTtl } from './utils.js';
|
|
9
|
-
import { Convert, logger } from '@enbox/common';
|
|
10
|
-
import { DwnInterfaceName, DwnMethodName } from '@enbox/dwn-sdk-js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Initiates the wallet connect process. Used when a client wants to obtain
|
|
14
|
-
* a did from a provider.
|
|
15
|
-
*/
|
|
16
|
-
async function initClient({
|
|
17
|
-
displayName,
|
|
18
|
-
connectServerUrl,
|
|
19
|
-
walletUri,
|
|
20
|
-
permissionRequests,
|
|
21
|
-
onWalletUriReady,
|
|
22
|
-
validatePin,
|
|
23
|
-
}: WalletConnectOptions): Promise<{
|
|
24
|
-
delegateGrants: EnboxConnectResponse['delegateGrants'];
|
|
25
|
-
delegatePortableDid: EnboxConnectResponse['delegatePortableDid'];
|
|
26
|
-
connectedDid: string;
|
|
27
|
-
} | undefined> {
|
|
28
|
-
// ephemeral client did for ECDH, signing, verification
|
|
29
|
-
const clientDid = await DidJwk.create();
|
|
30
|
-
|
|
31
|
-
// TODO: properly implement PKCE. this implementation is lacking server side validations and more.
|
|
32
|
-
// https://github.com/enboxorg/enbox/issues/829
|
|
33
|
-
// Derive the code challenge based on the code verifier
|
|
34
|
-
// const { codeChallengeBytes, codeChallengeBase64Url } =
|
|
35
|
-
// await Oidc.generateCodeChallenge();
|
|
36
|
-
const encryptionKey = CryptoUtils.randomBytes(32);
|
|
37
|
-
|
|
38
|
-
// Build callback URL for the connect request.
|
|
39
|
-
const callbackEndpoint = EnboxConnectProtocol.buildConnectUrl({
|
|
40
|
-
baseURL : connectServerUrl,
|
|
41
|
-
endpoint : 'callback',
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// Build the connect request.
|
|
45
|
-
const request = await EnboxConnectProtocol.createConnectRequest({
|
|
46
|
-
clientDid : clientDid.uri,
|
|
47
|
-
callbackUrl : callbackEndpoint,
|
|
48
|
-
permissionRequests : permissionRequests,
|
|
49
|
-
appName : displayName,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// Sign the request as a JWT.
|
|
53
|
-
const requestJwt = await EnboxConnectProtocol.signJwt({
|
|
54
|
-
did : clientDid,
|
|
55
|
-
data : request as unknown as Record<string, unknown>,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
if (!requestJwt) {
|
|
59
|
-
throw new Error('Unable to sign requestObject');
|
|
60
|
-
}
|
|
61
|
-
// Encrypt the request JWT with the symmetric key.
|
|
62
|
-
const requestObjectJwe = await EnboxConnectProtocol.encryptRequest({
|
|
63
|
-
jwt: requestJwt,
|
|
64
|
-
encryptionKey,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const pushedAuthorizationRequestEndpoint = EnboxConnectProtocol.buildConnectUrl({
|
|
68
|
-
baseURL : connectServerUrl,
|
|
69
|
-
endpoint : 'pushedAuthorizationRequest',
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const parResponse = await fetch(pushedAuthorizationRequestEndpoint, {
|
|
73
|
-
body : JSON.stringify({ request: requestObjectJwe }),
|
|
74
|
-
method : 'POST',
|
|
75
|
-
headers : {
|
|
76
|
-
'Content-Type': 'application/json',
|
|
77
|
-
},
|
|
78
|
-
signal: AbortSignal.timeout(30_000),
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
if (!parResponse.ok) {
|
|
82
|
-
throw new Error(`${parResponse.status}: ${parResponse.statusText}`);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const parData: ConnectPushedResponse = await parResponse.json();
|
|
86
|
-
|
|
87
|
-
// a deeplink to a compatible wallet. if the wallet scans this link it should receive
|
|
88
|
-
// a route to its Connect provider flow and the params of where to fetch the auth request.
|
|
89
|
-
logger.log(`Wallet URI: ${walletUri}`);
|
|
90
|
-
const generatedWalletUri = new URL(walletUri);
|
|
91
|
-
generatedWalletUri.searchParams.set('request_uri', parData.request_uri);
|
|
92
|
-
generatedWalletUri.searchParams.set(
|
|
93
|
-
'encryption_key',
|
|
94
|
-
Convert.uint8Array(encryptionKey).toBase64Url()
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
// call user's callback so they can send the URI to the wallet as they see fit
|
|
98
|
-
onWalletUriReady(generatedWalletUri.toString());
|
|
99
|
-
|
|
100
|
-
const tokenUrl = EnboxConnectProtocol.buildConnectUrl({
|
|
101
|
-
baseURL : connectServerUrl,
|
|
102
|
-
endpoint : 'token',
|
|
103
|
-
tokenParam : request.state,
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// subscribe to receiving a response from the wallet with default TTL. receive ciphertext of {@link EnboxConnectAuthResponse}
|
|
107
|
-
const authResponse = await pollWithTtl(() => fetch(tokenUrl, { signal: AbortSignal.timeout(30_000) }));
|
|
108
|
-
|
|
109
|
-
if (authResponse) {
|
|
110
|
-
const jwe = await authResponse?.text();
|
|
111
|
-
|
|
112
|
-
// Get the PIN from the user and use it as AAD to decrypt.
|
|
113
|
-
const pin = await validatePin();
|
|
114
|
-
const jwt = await EnboxConnectProtocol.decryptResponse(clientDid, jwe, pin);
|
|
115
|
-
const verifiedResponse = (await EnboxConnectProtocol.verifyJwt({
|
|
116
|
-
jwt,
|
|
117
|
-
})) as unknown as EnboxConnectResponse;
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
delegateGrants : verifiedResponse.delegateGrants,
|
|
121
|
-
delegatePortableDid : verifiedResponse.delegatePortableDid,
|
|
122
|
-
connectedDid : verifiedResponse.providerDid,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Options for initiating a wallet connect flow (remote, relay-mediated).
|
|
129
|
-
*/
|
|
130
|
-
export type WalletConnectOptions = {
|
|
131
|
-
/** The user-friendly name of the app, displayed in the wallet consent UI. */
|
|
132
|
-
displayName: string;
|
|
133
|
-
|
|
134
|
-
/** The URL of the connect server which relays messages between the app and wallet. */
|
|
135
|
-
connectServerUrl: string;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* The URI of the wallet app. Query params (`request_uri`, `encryption_key`)
|
|
139
|
-
* are appended and passed to `onWalletUriReady`.
|
|
140
|
-
* @example `enbox://connect` or `http://localhost:3000/`
|
|
141
|
-
*/
|
|
142
|
-
walletUri: string;
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* The protocols of permissions requested, along with the definition and
|
|
146
|
-
* permission scopes for each protocol. The key is the protocol URL and
|
|
147
|
-
* the value is an object with the protocol definition and the permission scopes.
|
|
148
|
-
*/
|
|
149
|
-
permissionRequests: ConnectPermissionRequest[];
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Called with the wallet URI including query params (`request_uri`, `encryption_key`).
|
|
153
|
-
* The app should render this as a QR code or use it as a deep link.
|
|
154
|
-
*
|
|
155
|
-
* @param uri - The wallet URI with connect payload.
|
|
156
|
-
*/
|
|
157
|
-
onWalletUriReady: (uri: string) => void;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Called to collect the PIN from the user. The PIN is used as AAD
|
|
161
|
-
* when decrypting the connect response from the relay.
|
|
162
|
-
*
|
|
163
|
-
* @returns A promise that resolves to the PIN as a string.
|
|
164
|
-
*/
|
|
165
|
-
validatePin: () => Promise<string>;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* The protocols of permissions requested, along with the definition and permission scopes for each protocol.
|
|
170
|
-
*/
|
|
171
|
-
export type ConnectPermissionRequest = {
|
|
172
|
-
/**
|
|
173
|
-
* The definition of the protocol the permissions are being requested for.
|
|
174
|
-
* In the event that the protocol is not already installed, the wallet will install this given protocol definition.
|
|
175
|
-
*/
|
|
176
|
-
protocolDefinition: DwnProtocolDefinition;
|
|
177
|
-
|
|
178
|
-
/** The scope of the permissions being requested for the given protocol */
|
|
179
|
-
permissionScopes: DwnPermissionScope[];
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Shorthand for the types of permissions that can be requested.
|
|
184
|
-
*/
|
|
185
|
-
export type Permission = 'write' | 'read' | 'delete' | 'query' | 'subscribe' | 'configure';
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* The options for creating a permission request for a given protocol.
|
|
189
|
-
*/
|
|
190
|
-
export type ProtocolPermissionOptions = {
|
|
191
|
-
/** The protocol definition for the protocol being requested */
|
|
192
|
-
definition: DwnProtocolDefinition;
|
|
193
|
-
|
|
194
|
-
/** The permissions being requested for the protocol */
|
|
195
|
-
permissions: Permission[];
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Creates a set of Dwn Permission Scopes to request for a given protocol.
|
|
200
|
-
*
|
|
201
|
-
* If no permissions are provided, the default is to request all relevant record permissions (write, read, delete, query, subscribe).
|
|
202
|
-
* 'configure' is not included by default, as this gives the application a lot of control over the protocol.
|
|
203
|
-
*/
|
|
204
|
-
function createPermissionRequestForProtocol({ definition, permissions }: ProtocolPermissionOptions): ConnectPermissionRequest {
|
|
205
|
-
const requests: DwnPermissionScope[] = [];
|
|
206
|
-
|
|
207
|
-
// Add the ability to query for the specific protocol
|
|
208
|
-
requests.push({
|
|
209
|
-
protocol : definition.protocol,
|
|
210
|
-
interface : DwnInterfaceName.Protocols,
|
|
211
|
-
method : DwnMethodName.Query,
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
// A Messages.Read grant is a unified scope that covers MessagesRead, MessagesSync, and MessagesSubscribe.
|
|
215
|
-
// This single grant enables sync and real-time subscriptions for the protocol.
|
|
216
|
-
requests.push({
|
|
217
|
-
protocol : definition.protocol,
|
|
218
|
-
interface : DwnInterfaceName.Messages,
|
|
219
|
-
method : DwnMethodName.Read,
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
// We also request any additional permissions the user has requested for this protocol
|
|
223
|
-
for (const permission of permissions) {
|
|
224
|
-
switch (permission) {
|
|
225
|
-
case 'write':
|
|
226
|
-
requests.push({
|
|
227
|
-
protocol : definition.protocol,
|
|
228
|
-
interface : DwnInterfaceName.Records,
|
|
229
|
-
method : DwnMethodName.Write,
|
|
230
|
-
});
|
|
231
|
-
break;
|
|
232
|
-
case 'read':
|
|
233
|
-
requests.push({
|
|
234
|
-
protocol : definition.protocol,
|
|
235
|
-
interface : DwnInterfaceName.Records,
|
|
236
|
-
method : DwnMethodName.Read,
|
|
237
|
-
});
|
|
238
|
-
break;
|
|
239
|
-
case 'delete':
|
|
240
|
-
requests.push({
|
|
241
|
-
protocol : definition.protocol,
|
|
242
|
-
interface : DwnInterfaceName.Records,
|
|
243
|
-
method : DwnMethodName.Delete,
|
|
244
|
-
});
|
|
245
|
-
break;
|
|
246
|
-
case 'query':
|
|
247
|
-
requests.push({
|
|
248
|
-
protocol : definition.protocol,
|
|
249
|
-
interface : DwnInterfaceName.Records,
|
|
250
|
-
method : DwnMethodName.Query,
|
|
251
|
-
});
|
|
252
|
-
break;
|
|
253
|
-
case 'subscribe':
|
|
254
|
-
requests.push({
|
|
255
|
-
protocol : definition.protocol,
|
|
256
|
-
interface : DwnInterfaceName.Records,
|
|
257
|
-
method : DwnMethodName.Subscribe,
|
|
258
|
-
});
|
|
259
|
-
break;
|
|
260
|
-
case 'configure':
|
|
261
|
-
requests.push({
|
|
262
|
-
protocol : definition.protocol,
|
|
263
|
-
interface : DwnInterfaceName.Protocols,
|
|
264
|
-
method : DwnMethodName.Configure,
|
|
265
|
-
});
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
return {
|
|
271
|
-
protocolDefinition : definition,
|
|
272
|
-
permissionScopes : requests,
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
export const WalletConnect = { initClient, createPermissionRequestForProtocol };
|
package/src/sync-api.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { EnboxPlatformAgent } from './types/agent.js';
|
|
2
|
-
import type { StartSyncParams, SyncConnectivityState, SyncEngine, SyncIdentityOptions } from './types/sync.js';
|
|
3
|
-
|
|
4
|
-
export type SyncApiParams = {
|
|
5
|
-
agent?: EnboxPlatformAgent;
|
|
6
|
-
syncEngine: SyncEngine;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export class AgentSyncApi implements SyncEngine {
|
|
10
|
-
/**
|
|
11
|
-
* Holds the instance of a `EnboxPlatformAgent` that represents the current execution context for
|
|
12
|
-
* the `AgentSyncApi`. This agent is used to interact with other Enbox agent components. It's vital
|
|
13
|
-
* to ensure this instance is set to correctly contextualize operations within the broader Enbox
|
|
14
|
-
* Agent framework.
|
|
15
|
-
*/
|
|
16
|
-
private _agent?: EnboxPlatformAgent;
|
|
17
|
-
|
|
18
|
-
private _syncEngine: SyncEngine;
|
|
19
|
-
|
|
20
|
-
constructor({ agent, syncEngine }: SyncApiParams) {
|
|
21
|
-
this._syncEngine = syncEngine;
|
|
22
|
-
this._agent = agent;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Retrieves the `EnboxPlatformAgent` execution context.
|
|
27
|
-
*
|
|
28
|
-
* @returns The `EnboxPlatformAgent` instance that represents the current execution context.
|
|
29
|
-
* @throws Will throw an error if the `agent` instance property is undefined.
|
|
30
|
-
*/
|
|
31
|
-
get agent(): EnboxPlatformAgent {
|
|
32
|
-
if (this._agent === undefined) {
|
|
33
|
-
throw new Error('AgentSyncApi: Unable to determine agent execution context.');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return this._agent;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
set agent(agent: EnboxPlatformAgent) {
|
|
40
|
-
this._agent = agent;
|
|
41
|
-
this._syncEngine.agent = agent;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
get connectivityState(): SyncConnectivityState {
|
|
45
|
-
return this._syncEngine.connectivityState;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public async registerIdentity(params: { did: string; options?: SyncIdentityOptions }): Promise<void> {
|
|
49
|
-
await this._syncEngine.registerIdentity(params);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public async unregisterIdentity(did: string): Promise<void> {
|
|
53
|
-
await this._syncEngine.unregisterIdentity(did);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public async getIdentityOptions(did: string): Promise<SyncIdentityOptions | undefined> {
|
|
57
|
-
return await this._syncEngine.getIdentityOptions(did);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public async updateIdentityOptions(params: { did: string, options: SyncIdentityOptions }): Promise<void> {
|
|
61
|
-
await this._syncEngine.updateIdentityOptions(params);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public sync(direction?: 'push' | 'pull'): Promise<void> {
|
|
65
|
-
return this._syncEngine.sync(direction);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
public startSync(params: StartSyncParams): Promise<void> {
|
|
69
|
-
return this._syncEngine.startSync(params);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public stopSync(timeout?: number): Promise<void> {
|
|
73
|
-
return this._syncEngine.stopSync(timeout);
|
|
74
|
-
}
|
|
75
|
-
}
|