@tari-project/wallet-daemon-signer 0.9.0 → 0.10.1

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/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { TariConnection } from "./webrtc";
2
2
  export * from "@tari-project/tari-permissions";
3
3
  export * from "./signer";
4
+ export * from "./provider";
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { TariConnection } from "./webrtc";
2
2
  export * from "@tari-project/tari-permissions";
3
3
  export * from "./signer";
4
+ export * from "./provider";
@@ -0,0 +1,21 @@
1
+ import { TariProvider } from "@tari-project/tari-provider";
2
+ import { GetSubstateRequest, GetTransactionResultResponse, ListSubstatesRequest, ListSubstatesResponse, Substate } from "@tari-project/tarijs-types";
3
+ import { GetTemplateDefinitionResponse, ListTemplatesResponse } from "@tari-project/typescript-bindings";
4
+ import { WalletDaemonClient } from "@tari-project/wallet_jrpc_client";
5
+ import { WalletDaemonFetchParameters, WalletDaemonParameters } from "./signer";
6
+ export declare class WalletDaemonTariProvider implements TariProvider {
7
+ providerName: string;
8
+ params: WalletDaemonParameters;
9
+ client: WalletDaemonClient;
10
+ private constructor();
11
+ static buildWebRtc(params: WalletDaemonParameters): Promise<WalletDaemonTariProvider>;
12
+ static buildFetch(params: WalletDaemonFetchParameters): Promise<WalletDaemonTariProvider>;
13
+ private static buildPermissions;
14
+ private getWebRtcTransport;
15
+ isConnected(): boolean;
16
+ getSubstate(req: GetSubstateRequest): Promise<Substate>;
17
+ getTemplateDefinition(template_address: string): Promise<GetTemplateDefinitionResponse>;
18
+ getTransactionResult(transactionId: string): Promise<GetTransactionResultResponse>;
19
+ listSubstates(req: ListSubstatesRequest): Promise<ListSubstatesResponse>;
20
+ listTemplates(_limit?: number): Promise<ListTemplatesResponse>;
21
+ }
@@ -0,0 +1,93 @@
1
+ import { transactionStatusFromStr, } from "@tari-project/tarijs-types";
2
+ import { substateIdToString, } from "@tari-project/typescript-bindings";
3
+ import { WalletDaemonClient } from "@tari-project/wallet_jrpc_client";
4
+ import { TariConnection } from "./webrtc";
5
+ import { WebRtcRpcTransport } from "./webrtc_transport";
6
+ import { TariPermissions } from "@tari-project/tari-permissions";
7
+ export class WalletDaemonTariProvider {
8
+ providerName = "WalletDaemonTariProvider";
9
+ params;
10
+ client;
11
+ constructor(params, connection) {
12
+ this.params = params;
13
+ this.client = connection;
14
+ }
15
+ static async buildWebRtc(params) {
16
+ const allPermissions = WalletDaemonTariProvider.buildPermissions(params);
17
+ let connection = new TariConnection(params.signalingServerUrl, params.webRtcConfig);
18
+ const client = WalletDaemonClient.new(WebRtcRpcTransport.new(connection));
19
+ await connection.init(allPermissions, (conn) => {
20
+ params.onConnection?.();
21
+ if (conn.token) {
22
+ client.setToken(conn.token);
23
+ }
24
+ });
25
+ return new WalletDaemonTariProvider(params, client);
26
+ }
27
+ static async buildFetch(params) {
28
+ const allPermissions = WalletDaemonTariProvider.buildPermissions(params);
29
+ const client = WalletDaemonClient.usingFetchTransport(params.serverUrl);
30
+ const plainPermissions = allPermissions.toJSON().flatMap((p) => (typeof p === "string" ? [p] : []));
31
+ const authResponse = await client.authRequest(plainPermissions);
32
+ await client.authAccept(authResponse, "WalletDaemon");
33
+ params.onConnection?.();
34
+ return new WalletDaemonTariProvider(params, client);
35
+ }
36
+ static buildPermissions(params) {
37
+ const allPermissions = new TariPermissions();
38
+ allPermissions.addPermissions(params.permissions);
39
+ if (params.optionalPermissions) {
40
+ allPermissions.addPermissions(params.optionalPermissions);
41
+ }
42
+ return allPermissions;
43
+ }
44
+ getWebRtcTransport() {
45
+ const transport = this.client.getTransport();
46
+ return transport instanceof WebRtcRpcTransport ? transport : undefined;
47
+ }
48
+ isConnected() {
49
+ return this.getWebRtcTransport()?.isConnected() || true;
50
+ }
51
+ async getSubstate(req) {
52
+ // TODO: Substate address cannot be converted to SubstateId directly - Perhaps we need to change the provider interface
53
+ const { record, value, } = await this.client.substatesGet({ substate_id: req.substate_address });
54
+ return {
55
+ value,
56
+ address: {
57
+ substate_id: substateIdToString(record.substate_id),
58
+ version: record.version,
59
+ },
60
+ };
61
+ }
62
+ async getTemplateDefinition(template_address) {
63
+ const { template_definition: definition } = await this.client.templatesGet({ template_address });
64
+ return {
65
+ // TODO: return module name from the wallet?
66
+ name: "<Unknown>",
67
+ definition,
68
+ };
69
+ }
70
+ async getTransactionResult(transactionId) {
71
+ const resp = await this.client.getTransactionResult({ transaction_id: transactionId });
72
+ return {
73
+ transaction_id: resp.transaction_id,
74
+ status: transactionStatusFromStr(resp.status),
75
+ result: resp.result || null,
76
+ };
77
+ }
78
+ async listSubstates(req) {
79
+ const resp = await this.client.substatesList(req);
80
+ return {
81
+ substates: resp.substates.map((s) => ({
82
+ substate_id: substateIdToString(s.substate_id),
83
+ module_name: s.module_name,
84
+ version: s.version,
85
+ template_address: s.template_address,
86
+ })),
87
+ };
88
+ }
89
+ listTemplates(_limit) {
90
+ // const resp = await this.client.templatesListAuthored({});
91
+ throw new Error("Listing all templates is not supported by WalletDaemonTariProvider.");
92
+ }
93
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/wallet-daemon-signer",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -10,11 +10,12 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "@tari-project/typescript-bindings": ">=1.9.1",
14
- "@tari-project/wallet_jrpc_client": "^1.6.0",
15
- "@tari-project/tari-permissions": "^0.9.0",
16
- "@tari-project/tari-signer": "^0.9.0",
17
- "@tari-project/tarijs-types": "^0.9.0"
13
+ "@tari-project/typescript-bindings": ">=1.10.2",
14
+ "@tari-project/wallet_jrpc_client": "^1.6.2",
15
+ "@tari-project/tari-permissions": "^0.10.1",
16
+ "@tari-project/tari-signer": "^0.10.1",
17
+ "@tari-project/tari-provider": "^0.10.1",
18
+ "@tari-project/tarijs-types": "^0.10.1"
18
19
  },
19
20
  "devDependencies": {
20
21
  "@types/node": "^22.13.1",