@tari-project/tarijs 0.12.1 → 0.12.2
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/.github/workflows/lint.yml +19 -0
- package/README.md +4 -1
- package/docusaurus/tari-docs/package.json +1 -1
- package/eslint.config.mjs +23 -6
- package/examples/vite-typescript-react/eslint.config.js +13 -10
- package/examples/vite-typescript-react/index.html +1 -1
- package/examples/vite-typescript-react/package.json +5 -6
- package/examples/vite-typescript-react/public/tari-logo.svg +18 -0
- package/examples/vite-typescript-react/tsconfig.json +2 -4
- package/knip.ts +18 -0
- package/package.json +7 -5
- package/packages/builders/package.json +3 -2
- package/packages/builders/src/helpers/submitTransaction.ts +11 -10
- package/packages/builders/src/helpers/workspace.ts +2 -2
- package/packages/builders/src/transaction/TransactionBuilder.ts +12 -13
- package/packages/indexer_provider/package.json +3 -2
- package/packages/indexer_provider/src/provider.ts +6 -7
- package/packages/indexer_provider/src/transports/IndexerProviderClient.ts +1 -0
- package/packages/indexer_provider/src/transports/fetch.ts +2 -2
- package/packages/indexer_provider/src/transports/rpc.ts +1 -0
- package/packages/metamask_signer/package.json +3 -2
- package/packages/metamask_signer/src/index.ts +7 -7
- package/packages/metamask_signer/src/utils.ts +36 -45
- package/packages/permissions/package.json +3 -2
- package/packages/permissions/src/helpers.ts +0 -1
- package/packages/permissions/src/permissions.ts +6 -13
- package/packages/react-mui-connect-button/package.json +3 -4
- package/packages/react-mui-connect-button/src/Logos.tsx +77 -48
- package/packages/react-mui-connect-button/src/TariConnectButton.tsx +1 -2
- package/packages/react-mui-connect-button/src/TariWalletSelectionDialog.tsx +64 -28
- package/packages/react-mui-connect-button/src/index.ts +6 -3
- package/packages/tari_provider/package.json +3 -2
- package/packages/tari_signer/package.json +3 -2
- package/packages/tari_universe/package.json +3 -2
- package/packages/tari_universe/src/types.ts +1 -0
- package/packages/tarijs/package.json +3 -2
- package/packages/tarijs/src/index.ts +2 -20
- package/packages/tarijs/src/templates/TestFaucet.ts +7 -2
- package/packages/tarijs/test/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +6 -9
- package/packages/tarijs_types/package.json +3 -2
- package/packages/tarijs_types/src/SubmitTransactionResponse.ts +3 -0
- package/packages/tarijs_types/src/TransactionArg.ts +1 -0
- package/packages/tarijs_types/src/consts.ts +1 -1
- package/packages/tarijs_types/src/helpers/hexString.ts +20 -19
- package/packages/tarijs_types/src/helpers/simpleResult.ts +23 -20
- package/packages/tarijs_types/src/helpers/txResult.ts +3 -4
- package/packages/tarijs_types/src/index.ts +9 -4
- package/packages/tarijs_types/src/signer.ts +3 -6
- package/packages/wallet_daemon/package.json +3 -2
- package/packages/wallet_daemon/src/provider.ts +14 -16
- package/packages/wallet_daemon/src/signer.ts +15 -17
- package/packages/wallet_daemon/src/webrtc.ts +18 -13
- package/packages/walletconnect/package.json +6 -6
- package/packages/walletconnect/src/index.ts +36 -22
- package/pnpm-workspace.yaml +8 -8
- package/tsconfig.json +1 -1
- package/typedoc.json +3 -2
- package/packages/react-mui-connect-button/src/defaultPermissions.ts +0 -0
- package/packages/tarijs_types/src/TransactionResult.ts +0 -16
|
@@ -1,23 +1,24 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
export function toHexString(byteArray: any): string {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
if (Array.isArray(byteArray)) {
|
|
4
|
+
return Array.from(byteArray, function (byte) {
|
|
5
|
+
return ("0" + (byte & 0xff).toString(16)).slice(-2);
|
|
6
|
+
}).join("");
|
|
7
|
+
}
|
|
8
|
+
if (byteArray === undefined) {
|
|
9
|
+
return "undefined";
|
|
10
|
+
}
|
|
11
|
+
// object might be a tagged object
|
|
12
|
+
if (byteArray["@@TAGGED@@"] !== undefined) {
|
|
13
|
+
return toHexString(byteArray["@@TAGGED@@"][1]);
|
|
14
|
+
}
|
|
15
|
+
return "Unsupported type";
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export function fromHexString(hexString: string) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
19
|
+
const res = [];
|
|
20
|
+
for (let i = 0; i < hexString.length; i += 2) {
|
|
21
|
+
res.push(Number("0x" + hexString.substring(i, i + 2)));
|
|
22
|
+
}
|
|
23
|
+
return res;
|
|
24
|
+
}
|
|
@@ -38,7 +38,11 @@ export class SimpleTransactionResult {
|
|
|
38
38
|
this.finalizeResult = result;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
static new(
|
|
41
|
+
static new(
|
|
42
|
+
transaction_id: TransactionId,
|
|
43
|
+
status: TransactionStatus,
|
|
44
|
+
result: FinalizeResult,
|
|
45
|
+
): SimpleTransactionResult {
|
|
42
46
|
return new SimpleTransactionResult(transaction_id, status, result);
|
|
43
47
|
}
|
|
44
48
|
|
|
@@ -125,7 +129,10 @@ export class SimpleTransactionResult {
|
|
|
125
129
|
|
|
126
130
|
const components = [];
|
|
127
131
|
for (const upSubstate of d.upSubstates()) {
|
|
128
|
-
if (
|
|
132
|
+
if (
|
|
133
|
+
upSubstate.type === "Component" &&
|
|
134
|
+
(upSubstate.substate as ComponentHeader).template_address === templateAddress
|
|
135
|
+
) {
|
|
129
136
|
components.push(SimpleComponent.new(upSubstate.id, upSubstate.version, upSubstate.substate as ComponentHeader));
|
|
130
137
|
}
|
|
131
138
|
}
|
|
@@ -164,7 +171,7 @@ export class SimpleTransactionResult {
|
|
|
164
171
|
}
|
|
165
172
|
|
|
166
173
|
public get diff(): Option<SimpleSubstateDiff> {
|
|
167
|
-
return this.accept.or(this.onlyFeeAccepted.map((x => x[0]))
|
|
174
|
+
return this.accept.or(this.onlyFeeAccepted.map((x) => x[0]));
|
|
168
175
|
}
|
|
169
176
|
|
|
170
177
|
public get onlyFeeAccepted(): Option<[SimpleSubstateDiff, RejectReason]> {
|
|
@@ -173,7 +180,7 @@ export class SimpleTransactionResult {
|
|
|
173
180
|
return None;
|
|
174
181
|
}
|
|
175
182
|
|
|
176
|
-
const [diff, reason] = result
|
|
183
|
+
const [diff, reason] = result.result.AcceptFeeRejectRest;
|
|
177
184
|
return Some([SimpleSubstateDiff.from(diff), reason]);
|
|
178
185
|
}
|
|
179
186
|
|
|
@@ -228,7 +235,6 @@ export class SimpleSubstateDiff {
|
|
|
228
235
|
constructor(diff: SubstateDiff) {
|
|
229
236
|
this.up_substates = diff.up_substates
|
|
230
237
|
.map(([id, val]: [SubstateId | string, Substate]) => {
|
|
231
|
-
|
|
232
238
|
if (!val.substate) {
|
|
233
239
|
console.error("Substate is missing in the accept result", id, val);
|
|
234
240
|
return null;
|
|
@@ -250,17 +256,15 @@ export class SimpleSubstateDiff {
|
|
|
250
256
|
})
|
|
251
257
|
.filter((x) => x !== null);
|
|
252
258
|
|
|
253
|
-
this.down_substates = diff.down_substates
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
});
|
|
263
|
-
|
|
259
|
+
this.down_substates = diff.down_substates.map(([id, version]: [SubstateId | string, number]) => {
|
|
260
|
+
const type = typeof id === "string" ? prefixToSubstateType(splitOnce(id, "_")![0]) : Object.keys(id)[0];
|
|
261
|
+
const idVal = substateIdToString(id);
|
|
262
|
+
return {
|
|
263
|
+
type: type! as SubstateType,
|
|
264
|
+
id: idVal,
|
|
265
|
+
version,
|
|
266
|
+
} as DownSubstate;
|
|
267
|
+
});
|
|
264
268
|
|
|
265
269
|
this.fee_withdrawals = diff.fee_withdrawals;
|
|
266
270
|
}
|
|
@@ -283,7 +287,7 @@ export class SimpleSubstateDiff {
|
|
|
283
287
|
}
|
|
284
288
|
|
|
285
289
|
export type AnySubstate =
|
|
286
|
-
ComponentHeader
|
|
290
|
+
| ComponentHeader
|
|
287
291
|
| Resource
|
|
288
292
|
| Vault
|
|
289
293
|
| UnclaimedConfidentialOutput
|
|
@@ -296,7 +300,7 @@ export type UpSubstate = {
|
|
|
296
300
|
type: SubstateType;
|
|
297
301
|
id: string;
|
|
298
302
|
version: number;
|
|
299
|
-
substate: AnySubstate
|
|
303
|
+
substate: AnySubstate;
|
|
300
304
|
};
|
|
301
305
|
|
|
302
306
|
export type DownSubstate = {
|
|
@@ -337,9 +341,8 @@ export class SimpleComponent {
|
|
|
337
341
|
}
|
|
338
342
|
}
|
|
339
343
|
|
|
340
|
-
|
|
341
344
|
export interface GetAccountsResult {
|
|
342
345
|
substate_id: string;
|
|
343
346
|
version: number;
|
|
344
347
|
account: BuiltInAccount;
|
|
345
|
-
}
|
|
348
|
+
}
|
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
ResourceAddress,
|
|
8
8
|
Amount,
|
|
9
9
|
substateIdToString,
|
|
10
|
-
ComponentAddress,
|
|
10
|
+
ComponentAddress,
|
|
11
|
+
FinalizeResult,
|
|
11
12
|
} from "@tari-project/typescript-bindings";
|
|
12
13
|
import { UpSubstates } from "../SubstateDiff";
|
|
13
14
|
|
|
@@ -37,9 +38,7 @@ export const txResultCheck = {
|
|
|
37
38
|
isReject: (result: FinalizeResult): boolean => {
|
|
38
39
|
return "Reject" in result.result;
|
|
39
40
|
},
|
|
40
|
-
isAcceptFeeRejectRest: (
|
|
41
|
-
result: FinalizeResult,
|
|
42
|
-
): boolean => {
|
|
41
|
+
isAcceptFeeRejectRest: (result: FinalizeResult): boolean => {
|
|
43
42
|
return "AcceptFeeRejectRest" in result.result;
|
|
44
43
|
},
|
|
45
44
|
};
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
ComponentAddress,
|
|
3
|
+
ResourceAddress,
|
|
4
|
+
PublishedTemplateAddress,
|
|
5
|
+
Epoch,
|
|
6
|
+
Transaction,
|
|
7
|
+
TransactionResult,
|
|
8
|
+
} from "@tari-project/typescript-bindings";
|
|
2
9
|
export { Amount } from "./Amount";
|
|
3
10
|
export { BuiltInAccount, VaultSubstate } from "./Account";
|
|
4
11
|
export { TransactionArg } from "./TransactionArg";
|
|
@@ -6,11 +13,9 @@ export { ConfidentialClaim } from "./ConfidentialClaim";
|
|
|
6
13
|
export { ConfidentialOutput } from "./ConfidentialOutput";
|
|
7
14
|
export { ConfidentialWithdrawProof } from "./ConfidentialWithdrawProof";
|
|
8
15
|
export { GetTransactionResultResponse } from "./GetTransactionResultResponse";
|
|
16
|
+
export { SubmitTransactionResponse } from "./SubmitTransactionResponse";
|
|
9
17
|
export { DownSubstates, UpSubstates } from "./SubstateDiff";
|
|
10
18
|
export { SubstateType } from "./SubstateType";
|
|
11
|
-
export {
|
|
12
|
-
SubmitTransactionResponse,
|
|
13
|
-
} from "./TransactionResult";
|
|
14
19
|
export { TransactionSignature } from "./TransactionSignature";
|
|
15
20
|
export { TransactionStatus, transactionStatusFromStr } from "./TransactionStatus";
|
|
16
21
|
export { WorkspaceArg } from "./Workspace";
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SubstateType,
|
|
3
|
-
TemplateDef,
|
|
4
|
-
UnsignedTransactionV1,
|
|
5
|
-
} from "@tari-project/typescript-bindings";
|
|
1
|
+
import { SubstateType, TemplateDef, UnsignedTransactionV1 } from "@tari-project/typescript-bindings";
|
|
6
2
|
|
|
7
3
|
export type SubstateMetadata = {
|
|
8
4
|
substate_id: string;
|
|
@@ -17,7 +13,7 @@ export type ReqSubstate = {
|
|
|
17
13
|
};
|
|
18
14
|
|
|
19
15
|
export type SubmitTransactionRequest = {
|
|
20
|
-
transaction: UnsignedTransactionV1
|
|
16
|
+
transaction: UnsignedTransactionV1;
|
|
21
17
|
account_id: number;
|
|
22
18
|
detect_inputs_use_unversioned: boolean;
|
|
23
19
|
};
|
|
@@ -44,6 +40,7 @@ export interface VaultBalances {
|
|
|
44
40
|
export type TemplateDefinition = TemplateDef;
|
|
45
41
|
|
|
46
42
|
export interface Substate {
|
|
43
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
47
44
|
value: any;
|
|
48
45
|
address: {
|
|
49
46
|
substate_id: string;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/wallet-daemon-signer",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "tsc -b"
|
|
10
|
+
"build": "tsc -b",
|
|
11
|
+
"lint": "eslint src/"
|
|
11
12
|
},
|
|
12
13
|
"keywords": [],
|
|
13
14
|
"author": "The Tari Community",
|
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
GetTransactionResultResponse,
|
|
5
5
|
ListSubstatesRequest,
|
|
6
6
|
ListSubstatesResponse,
|
|
7
|
-
Substate,
|
|
7
|
+
Substate,
|
|
8
|
+
SubstateMetadata,
|
|
8
9
|
transactionStatusFromStr,
|
|
9
10
|
} from "@tari-project/tarijs-types";
|
|
10
11
|
import {
|
|
11
12
|
GetTemplateDefinitionResponse,
|
|
12
13
|
ListTemplatesResponse,
|
|
13
|
-
SubstateId,
|
|
14
14
|
substateIdToString,
|
|
15
15
|
} from "@tari-project/typescript-bindings";
|
|
16
16
|
import { WalletDaemonClient } from "@tari-project/wallet_jrpc_client";
|
|
@@ -31,7 +31,7 @@ export class WalletDaemonTariProvider implements TariProvider {
|
|
|
31
31
|
|
|
32
32
|
static async buildWebRtc(params: WalletDaemonParameters): Promise<WalletDaemonTariProvider> {
|
|
33
33
|
const allPermissions = WalletDaemonTariProvider.buildPermissions(params);
|
|
34
|
-
|
|
34
|
+
const connection = new TariConnection(params.signalingServerUrl, params.webRtcConfig);
|
|
35
35
|
const client = WalletDaemonClient.new(WebRtcRpcTransport.new(connection));
|
|
36
36
|
await connection.init(allPermissions, (conn) => {
|
|
37
37
|
params.onConnection?.();
|
|
@@ -42,7 +42,6 @@ export class WalletDaemonTariProvider implements TariProvider {
|
|
|
42
42
|
return new WalletDaemonTariProvider(params, client);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
46
45
|
static async buildFetch(params: WalletDaemonFetchParameters) {
|
|
47
46
|
const allPermissions = WalletDaemonTariProvider.buildPermissions(params);
|
|
48
47
|
const client = WalletDaemonClient.usingFetchTransport(params.serverUrl);
|
|
@@ -75,9 +74,7 @@ export class WalletDaemonTariProvider implements TariProvider {
|
|
|
75
74
|
|
|
76
75
|
async getSubstate(req: GetSubstateRequest): Promise<Substate> {
|
|
77
76
|
// TODO: Substate address cannot be converted to SubstateId directly - Perhaps we need to change the provider interface
|
|
78
|
-
const {
|
|
79
|
-
substate,
|
|
80
|
-
} = await this.client.substatesGet({ substate_id: req.substate_address });
|
|
77
|
+
const { substate } = await this.client.substatesGet({ substate_id: req.substate_address });
|
|
81
78
|
if (!substate) {
|
|
82
79
|
throw new Error(`Substate not found for address: ${req.substate_address}`);
|
|
83
80
|
}
|
|
@@ -115,12 +112,15 @@ export class WalletDaemonTariProvider implements TariProvider {
|
|
|
115
112
|
const resp = await this.client.substatesList(req);
|
|
116
113
|
|
|
117
114
|
return {
|
|
118
|
-
substates: resp.substates.map(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
115
|
+
substates: resp.substates.map(
|
|
116
|
+
(s) =>
|
|
117
|
+
({
|
|
118
|
+
substate_id: substateIdToString(s.substate_id),
|
|
119
|
+
module_name: s.module_name,
|
|
120
|
+
version: s.version,
|
|
121
|
+
template_address: s.template_address,
|
|
122
|
+
} as SubstateMetadata),
|
|
123
|
+
),
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
126
|
|
|
@@ -128,6 +128,4 @@ export class WalletDaemonTariProvider implements TariProvider {
|
|
|
128
128
|
// const resp = await this.client.templatesListAuthored({});
|
|
129
129
|
throw new Error("Listing all templates is not supported by WalletDaemonTariProvider.");
|
|
130
130
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
131
|
+
}
|
|
@@ -43,7 +43,6 @@ export interface WalletDaemonFetchParameters extends WalletDaemonBaseParameters
|
|
|
43
43
|
serverUrl: string;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
46
|
export class WalletDaemonTariSigner implements TariSigner {
|
|
48
47
|
public signerName = "WalletDaemon";
|
|
49
48
|
params: WalletDaemonParameters;
|
|
@@ -56,7 +55,7 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
56
55
|
|
|
57
56
|
static async build(params: WalletDaemonParameters): Promise<WalletDaemonTariSigner> {
|
|
58
57
|
const allPermissions = WalletDaemonTariSigner.buildPermissions(params);
|
|
59
|
-
|
|
58
|
+
const connection = new TariConnection(params.signalingServerUrl, params.webRtcConfig);
|
|
60
59
|
const client = WalletDaemonClient.new(WebRtcRpcTransport.new(connection));
|
|
61
60
|
await connection.init(allPermissions, (conn) => {
|
|
62
61
|
params.onConnection?.();
|
|
@@ -135,6 +134,7 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
135
134
|
}
|
|
136
135
|
|
|
137
136
|
public async getAccount(): Promise<AccountData> {
|
|
137
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
138
138
|
const { account, public_key } = (await this.client.accountsGetDefault({})) as any;
|
|
139
139
|
const address = typeof account.address === "object" ? account.address.Component : account.address;
|
|
140
140
|
const { balances } = await this.client.accountsGetBalances({
|
|
@@ -163,9 +163,7 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
public async getSubstate(substateId: string): Promise<Substate> {
|
|
166
|
-
const {
|
|
167
|
-
substate,
|
|
168
|
-
} = await this.client.substatesGet({ substate_id: substateId });
|
|
166
|
+
const { substate } = await this.client.substatesGet({ substate_id: substateId });
|
|
169
167
|
if (!substate) {
|
|
170
168
|
throw new Error(`Substate not found for address: ${substateId}`);
|
|
171
169
|
}
|
|
@@ -212,16 +210,16 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
212
210
|
}
|
|
213
211
|
|
|
214
212
|
public async getTemplateDefinition(template_address: string): Promise<TemplateDefinition> {
|
|
215
|
-
|
|
213
|
+
const resp = await this.client.templatesGet({ template_address });
|
|
216
214
|
return resp.template_definition as TemplateDefinition;
|
|
217
215
|
}
|
|
218
216
|
|
|
219
217
|
public async getConfidentialVaultBalances({
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
218
|
+
vault_id,
|
|
219
|
+
view_key_id,
|
|
220
|
+
maximum_expected_value = null,
|
|
221
|
+
minimum_expected_value = null,
|
|
222
|
+
}: ConfidentialViewVaultBalanceRequest): Promise<VaultBalances> {
|
|
225
223
|
const res = await this.client.viewVaultBalance({
|
|
226
224
|
view_key_id,
|
|
227
225
|
vault_id,
|
|
@@ -232,11 +230,11 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
232
230
|
}
|
|
233
231
|
|
|
234
232
|
public async listSubstates({
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
233
|
+
filter_by_template,
|
|
234
|
+
filter_by_type,
|
|
235
|
+
limit,
|
|
236
|
+
offset,
|
|
237
|
+
}: ListSubstatesRequest): Promise<ListSubstatesResponse> {
|
|
240
238
|
const resp = await this.client.substatesList({
|
|
241
239
|
filter_by_template,
|
|
242
240
|
filter_by_type,
|
|
@@ -244,7 +242,7 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
244
242
|
offset,
|
|
245
243
|
} as SubstatesListRequest);
|
|
246
244
|
|
|
247
|
-
const substates = resp.substates.map((s) => ({
|
|
245
|
+
const substates = resp.substates.map((s: any) => ({
|
|
248
246
|
substate_id: typeof s.substate_id === "string" ? s.substate_id : substateIdToString(s.substate_id),
|
|
249
247
|
module_name: s.module_name,
|
|
250
248
|
version: s.version,
|
|
@@ -26,12 +26,12 @@ class SignalingServer {
|
|
|
26
26
|
console.log("jsonRpc", method, token, params);
|
|
27
27
|
let id = 0;
|
|
28
28
|
id += 1;
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const address = this._server_url;
|
|
30
|
+
const headers: { [key: string]: string } = { "Content-Type": "application/json" };
|
|
31
31
|
if (token) {
|
|
32
32
|
headers["Authorization"] = `Bearer ${token}`;
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
const response = await fetch(address, {
|
|
35
35
|
method: "POST",
|
|
36
36
|
body: JSON.stringify({
|
|
37
37
|
method: method,
|
|
@@ -41,7 +41,7 @@ class SignalingServer {
|
|
|
41
41
|
}),
|
|
42
42
|
headers: headers,
|
|
43
43
|
});
|
|
44
|
-
|
|
44
|
+
const json = await response.json();
|
|
45
45
|
if (json.error) {
|
|
46
46
|
throw json.error;
|
|
47
47
|
}
|
|
@@ -99,7 +99,7 @@ export class TariConnection {
|
|
|
99
99
|
await this._signalingServer.initToken(permissions);
|
|
100
100
|
// Setup our receiving end
|
|
101
101
|
this._dataChannel.onmessage = (message) => {
|
|
102
|
-
|
|
102
|
+
const response = JSON.parse(message.data);
|
|
103
103
|
console.log("response", response);
|
|
104
104
|
|
|
105
105
|
if (!this._callbacks[response.id]) {
|
|
@@ -107,7 +107,7 @@ export class TariConnection {
|
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
109
|
// The response should contain id, to identify the Promise.resolve, that is waiting for this result
|
|
110
|
-
|
|
110
|
+
const [resolve, reject] = this._callbacks[response.id];
|
|
111
111
|
delete this._callbacks[response.id];
|
|
112
112
|
if (response.payload?.error) {
|
|
113
113
|
reject(new Error(response.payload.error));
|
|
@@ -119,8 +119,8 @@ export class TariConnection {
|
|
|
119
119
|
// This should be removed before the release, but it's good for debugging.
|
|
120
120
|
console.log("Data channel is open!");
|
|
121
121
|
|
|
122
|
-
this.sendMessage({ id: 0, jsonrpc: "2.0", method: "get.token", params: {} }, this._signalingServer.token)
|
|
123
|
-
|
|
122
|
+
this.sendMessage({ id: 0, jsonrpc: "2.0", method: "get.token", params: {} }, this._signalingServer.token).then(
|
|
123
|
+
(walletToken: unknown) => {
|
|
124
124
|
if (typeof walletToken !== "string") {
|
|
125
125
|
throw Error("Received invalid JWT from wallet daemon");
|
|
126
126
|
}
|
|
@@ -131,7 +131,8 @@ export class TariConnection {
|
|
|
131
131
|
if (this.onConnection) {
|
|
132
132
|
this.onConnection(this);
|
|
133
133
|
}
|
|
134
|
-
}
|
|
134
|
+
},
|
|
135
|
+
);
|
|
135
136
|
};
|
|
136
137
|
this._peerConnection.onicecandidate = (event) => {
|
|
137
138
|
console.log("event", event);
|
|
@@ -160,13 +161,13 @@ export class TariConnection {
|
|
|
160
161
|
private async setAnswer() {
|
|
161
162
|
// This is called once the other end got the offer and ices and created and store an answer and its ice candidates
|
|
162
163
|
// We get its answer sdp
|
|
163
|
-
|
|
164
|
+
const sdp = await this._signalingServer.getAnswer();
|
|
164
165
|
|
|
165
166
|
// And its ice candidates
|
|
166
|
-
|
|
167
|
+
const iceCandidates = await this._signalingServer.getIceCandidates();
|
|
167
168
|
|
|
168
169
|
// For us the answer is remote sdp
|
|
169
|
-
|
|
170
|
+
const answer = new RTCSessionDescription({ sdp, type: "answer" });
|
|
170
171
|
this._peerConnection.setRemoteDescription(answer);
|
|
171
172
|
|
|
172
173
|
// We add all the ice candidates to connect, the other end is doing the same with our ice candidates
|
|
@@ -199,7 +200,11 @@ export class TariConnection {
|
|
|
199
200
|
}
|
|
200
201
|
|
|
201
202
|
// If the last parameter has timeout property e.g. {timeout:1000}, it set the timeout for this call.
|
|
202
|
-
async sendMessage<T>(
|
|
203
|
+
async sendMessage<T>(
|
|
204
|
+
request: transports.RpcRequest,
|
|
205
|
+
token: string | undefined,
|
|
206
|
+
timeout_secs: number | null = null,
|
|
207
|
+
): Promise<T> {
|
|
203
208
|
if (!this.isConnected) {
|
|
204
209
|
throw new Error("WALLET_DAEMON_NOT_CONNECTED");
|
|
205
210
|
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/wallet-connect-signer",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "tsc -b"
|
|
10
|
+
"build": "tsc -b",
|
|
11
|
+
"lint": "eslint src/"
|
|
11
12
|
},
|
|
12
13
|
"keywords": [],
|
|
13
14
|
"author": "The Tari Community",
|
|
14
15
|
"license": "ISC",
|
|
15
16
|
"dependencies": {
|
|
17
|
+
"@reown/appkit": "catalog:",
|
|
18
|
+
"@tari-project/tari-permissions": "workspace:",
|
|
16
19
|
"@tari-project/tari-signer": "workspace:^",
|
|
17
|
-
"@tari-project/tarijs-builders": "workspace
|
|
20
|
+
"@tari-project/tarijs-builders": "workspace:*",
|
|
18
21
|
"@tari-project/tarijs-types": "workspace:^",
|
|
19
22
|
"@tari-project/typescript-bindings": "catalog:",
|
|
20
|
-
"@tari-project/wallet_jrpc_client": "catalog:",
|
|
21
|
-
"@tari-project/tari-permissions": "workspace:",
|
|
22
|
-
"@walletconnect/modal": "catalog:",
|
|
23
23
|
"@walletconnect/universal-provider": "catalog:"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TariSigner } from "@tari-project/tari-signer";
|
|
2
2
|
import UniversalProvider from "@walletconnect/universal-provider";
|
|
3
|
-
import {
|
|
3
|
+
import { AppKitNetwork, mainnet, sepolia } from "@reown/appkit/networks";
|
|
4
|
+
import { createAppKit } from "@reown/appkit/core";
|
|
4
5
|
import {
|
|
5
6
|
convertStringToTransactionStatus,
|
|
6
7
|
GetTransactionResultResponse,
|
|
@@ -69,41 +70,54 @@ export class WalletConnectTariSigner implements TariSigner {
|
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
async connect(): Promise<() => Promise<void>> {
|
|
72
|
-
if (this.wcProvider && this.wcSession)
|
|
73
|
-
|
|
73
|
+
if (this.wcProvider && this.wcSession)
|
|
74
|
+
return async () => {
|
|
75
|
+
// No-op if already connected
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const metadata = {
|
|
79
|
+
name: "Tari Universe",
|
|
80
|
+
description: "Tari Universe Wallet",
|
|
81
|
+
url: "https://www.tari.com",
|
|
82
|
+
icons: ["https://tari.com/assets/img/node-icon-alt.svg"],
|
|
74
83
|
};
|
|
75
84
|
|
|
76
|
-
// initialize WalletConnect
|
|
77
85
|
const projectId = this.params.projectId;
|
|
78
86
|
const provider = await UniversalProvider.init({
|
|
79
87
|
projectId,
|
|
80
88
|
// TODO: parameterize the relay URL
|
|
81
89
|
// relayUrl: "wss://relay.walletconnect.com",
|
|
90
|
+
metadata,
|
|
82
91
|
});
|
|
83
92
|
|
|
84
93
|
const sessionProperties = {
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
required_permissions: JSON.stringify(this.params.requiredPermissions) || "[]",
|
|
95
|
+
optional_permissions: JSON.stringify(this.params.optionalPermissions) || "[]",
|
|
87
96
|
};
|
|
88
97
|
const connectParams = {
|
|
89
98
|
...walletConnectParams,
|
|
90
99
|
sessionProperties,
|
|
91
100
|
};
|
|
92
101
|
|
|
93
|
-
|
|
102
|
+
const networks: [AppKitNetwork, ...AppKitNetwork[]] = [mainnet, sepolia];
|
|
103
|
+
|
|
94
104
|
const { uri, approval } = await provider.client.connect(connectParams);
|
|
95
105
|
return async () => {
|
|
96
|
-
const walletConnectModal =
|
|
97
|
-
projectId,
|
|
106
|
+
const walletConnectModal = createAppKit({
|
|
107
|
+
projectId: projectId,
|
|
108
|
+
networks: networks,
|
|
109
|
+
universalProvider: provider,
|
|
110
|
+
manualWCControl: true,
|
|
98
111
|
});
|
|
112
|
+
|
|
99
113
|
if (uri) {
|
|
100
|
-
await walletConnectModal.
|
|
114
|
+
await walletConnectModal.open({ uri });
|
|
101
115
|
}
|
|
102
116
|
|
|
103
117
|
// wait for the wallet to approve the connection
|
|
104
118
|
console.log("waiting for session approval from the wallet app");
|
|
105
119
|
const session = await approval();
|
|
106
|
-
walletConnectModal.
|
|
120
|
+
walletConnectModal.close();
|
|
107
121
|
|
|
108
122
|
// at this point session is open
|
|
109
123
|
console.log("session approved by the wallet");
|
|
@@ -177,11 +191,11 @@ export class WalletConnectTariSigner implements TariSigner {
|
|
|
177
191
|
}
|
|
178
192
|
|
|
179
193
|
public async listSubstates({
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
194
|
+
filter_by_template,
|
|
195
|
+
filter_by_type,
|
|
196
|
+
limit,
|
|
197
|
+
offset,
|
|
198
|
+
}: ListSubstatesRequest): Promise<ListSubstatesResponse> {
|
|
185
199
|
const method = "tari_listSubstates";
|
|
186
200
|
const params = {
|
|
187
201
|
filter_by_template,
|
|
@@ -245,7 +259,7 @@ export class WalletConnectTariSigner implements TariSigner {
|
|
|
245
259
|
}
|
|
246
260
|
|
|
247
261
|
async getTemplateDefinition(template_address: string): Promise<TemplateDefinition> {
|
|
248
|
-
|
|
262
|
+
const resp = await this.sendRequest("tari_getTemplate", { template_address });
|
|
249
263
|
return resp.template_definition as TemplateDefinition;
|
|
250
264
|
}
|
|
251
265
|
|
|
@@ -255,11 +269,11 @@ export class WalletConnectTariSigner implements TariSigner {
|
|
|
255
269
|
}
|
|
256
270
|
|
|
257
271
|
async getConfidentialVaultBalances({
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
272
|
+
vault_id,
|
|
273
|
+
view_key_id,
|
|
274
|
+
maximum_expected_value = null,
|
|
275
|
+
minimum_expected_value = null,
|
|
276
|
+
}: ConfidentialViewVaultBalanceRequest): Promise<VaultBalances> {
|
|
263
277
|
const method = "tari_viewConfidentialVaultBalance";
|
|
264
278
|
const params = {
|
|
265
279
|
view_key_id,
|