@tari-project/wallet-daemon-signer 0.8.0 → 0.10.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/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,98 @@
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({
80
+ filter_by_template: req.filter_by_template,
81
+ filter_by_type: req.filter_by_type,
82
+ limit: req.limit ? BigInt(req.limit) : null,
83
+ offset: req.offset ? BigInt(req.offset) : null,
84
+ });
85
+ return {
86
+ substates: resp.substates.map((s) => ({
87
+ substate_id: substateIdToString(s.substate_id),
88
+ module_name: s.module_name,
89
+ version: s.version,
90
+ template_address: s.template_address,
91
+ })),
92
+ };
93
+ }
94
+ listTemplates(_limit) {
95
+ // const resp = await this.client.templatesListAuthored({});
96
+ throw new Error("Listing all templates is not supported by WalletDaemonTariProvider.");
97
+ }
98
+ }
package/dist/signer.js CHANGED
@@ -115,28 +115,14 @@ export class WalletDaemonTariSigner {
115
115
  async submitTransaction(req) {
116
116
  const params = {
117
117
  transaction: {
118
- V1: {
119
- network: req.network,
120
- instructions: req.instructions,
121
- fee_instructions: req.fee_instructions,
122
- inputs: req.required_substates.map((s) => ({
123
- // TODO: Hmm The bindings want a SubstateId object, but the wallet only wants a string. Any is used to skip type checking here
124
- substate_id: s.substate_id,
125
- version: s.version ?? null,
126
- })),
127
- min_epoch: null,
128
- max_epoch: null,
129
- dry_run: req.is_dry_run,
130
- is_seal_signer_authorized: req.is_seal_signer_authorized,
131
- },
118
+ V1: req.transaction,
132
119
  },
133
120
  signing_key_index: req.account_id,
134
- autofill_inputs: [],
135
121
  detect_inputs: true,
136
122
  proof_ids: [],
137
123
  detect_inputs_use_unversioned: req.detect_inputs_use_unversioned,
138
124
  };
139
- const res = req.is_dry_run
125
+ const res = req.transaction.dry_run
140
126
  ? await this.client.submitTransactionDryRun(params)
141
127
  : await this.client.submitTransaction(params);
142
128
  return { transaction_id: res.transaction_id };
package/dist/webrtc.js CHANGED
@@ -1,4 +1,4 @@
1
- class SignaligServer {
1
+ class SignalingServer {
2
2
  _token;
3
3
  _server_url;
4
4
  constructor(server_url) {
@@ -70,7 +70,7 @@ export class TariConnection {
70
70
  constructor(signalig_server_url, config) {
71
71
  this._peerConnection = new RTCPeerConnection(config || this.config());
72
72
  this._dataChannel = this._peerConnection.createDataChannel("tari-data");
73
- this._signalingServer = new SignaligServer(signalig_server_url);
73
+ this._signalingServer = new SignalingServer(signalig_server_url);
74
74
  this._callbacks = {};
75
75
  }
76
76
  get token() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/wallet-daemon-signer",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
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.0",
13
+ "@tari-project/typescript-bindings": ">=1.9.1",
14
14
  "@tari-project/wallet_jrpc_client": "^1.6.0",
15
- "@tari-project/tari-permissions": "^0.8.0",
16
- "@tari-project/tari-signer": "^0.8.0",
17
- "@tari-project/tarijs-types": "^0.8.0"
15
+ "@tari-project/tari-permissions": "^0.10.0",
16
+ "@tari-project/tari-signer": "^0.10.0",
17
+ "@tari-project/tarijs-types": "^0.10.0",
18
+ "@tari-project/tari-provider": "^0.10.0"
18
19
  },
19
20
  "devDependencies": {
20
21
  "@types/node": "^22.13.1",