@tari-project/tarijs 0.12.1 → 0.13.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/.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 +24 -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_signer/src/TariSigner.ts +7 -0
- package/packages/tari_universe/package.json +3 -2
- package/packages/tari_universe/src/signer.ts +16 -0
- 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 +38 -17
- package/packages/wallet_daemon/src/webrtc.ts +18 -13
- package/packages/walletconnect/package.json +6 -6
- package/packages/walletconnect/src/index.ts +60 -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
|
@@ -14,10 +14,14 @@ import { SignerRequest, SignerMethodNames, SignerReturnType, TariUniverseSignerP
|
|
|
14
14
|
import { sendSignerCall } from "./utils";
|
|
15
15
|
import { TariSigner } from "@tari-project/tari-signer";
|
|
16
16
|
import {
|
|
17
|
+
AccountGetResponse,
|
|
17
18
|
AccountsGetBalancesResponse,
|
|
19
|
+
AccountsListRequest,
|
|
20
|
+
AccountsListResponse,
|
|
18
21
|
ConfidentialViewVaultBalanceRequest,
|
|
19
22
|
ListAccountNftRequest,
|
|
20
23
|
ListAccountNftResponse,
|
|
24
|
+
WalletGetInfoResponse,
|
|
21
25
|
} from "@tari-project/typescript-bindings";
|
|
22
26
|
|
|
23
27
|
export class TariUniverseSigner implements TariSigner {
|
|
@@ -83,10 +87,18 @@ export class TariUniverseSigner implements TariSigner {
|
|
|
83
87
|
return this.sendRequest({ methodName: "requestParentSize", args: [] });
|
|
84
88
|
}
|
|
85
89
|
|
|
90
|
+
public async accountsList(req: AccountsListRequest): Promise<AccountsListResponse> {
|
|
91
|
+
return this.sendRequest({ methodName: "accountsList", args: [req] });
|
|
92
|
+
}
|
|
93
|
+
|
|
86
94
|
public async getAccount(): Promise<AccountData> {
|
|
87
95
|
return this.sendRequest({ methodName: "getAccount", args: [] });
|
|
88
96
|
}
|
|
89
97
|
|
|
98
|
+
public async getAccountByAddress(address: string): Promise<AccountGetResponse> {
|
|
99
|
+
return this.sendRequest({ methodName: "getAccountByAddress", args: [address] });
|
|
100
|
+
}
|
|
101
|
+
|
|
90
102
|
public async getAccountBalances(componentAddress: string): Promise<AccountsGetBalancesResponse> {
|
|
91
103
|
return this.sendRequest({
|
|
92
104
|
methodName: "getAccountBalances",
|
|
@@ -126,4 +138,8 @@ export class TariUniverseSigner implements TariSigner {
|
|
|
126
138
|
public async getNftsFromAccountBalances(req: ListAccountNftFromBalancesRequest): Promise<ListAccountNftResponse> {
|
|
127
139
|
return this.sendRequest({ methodName: "getNftsFromAccountBalances", args: [req] });
|
|
128
140
|
}
|
|
141
|
+
|
|
142
|
+
public async getWalletInfo(): Promise<WalletGetInfoResponse> {
|
|
143
|
+
return this.sendRequest({ methodName: "getWalletInfo", args: [] });
|
|
144
|
+
}
|
|
129
145
|
}
|
|
@@ -14,6 +14,7 @@ export type WindowSize = {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export type PickMatching<T, V> = { [K in keyof T as T[K] extends V ? K : never]: T[K] };
|
|
17
|
+
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
|
|
17
18
|
export type ExtractMethods<T> = PickMatching<T, Function>;
|
|
18
19
|
export type SignerMethods = ExtractMethods<TariUniverseSigner>;
|
|
19
20
|
export type SignerMethodNames = keyof SignerMethods;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/tarijs-all",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc -b",
|
|
11
11
|
"test": "vitest run unit-tests",
|
|
12
|
-
"integration-tests": "vitest run integration-tests"
|
|
12
|
+
"integration-tests": "vitest run integration-tests",
|
|
13
|
+
"lint": "eslint src/"
|
|
13
14
|
},
|
|
14
15
|
"keywords": [],
|
|
15
16
|
"author": "The Tari Community",
|
|
@@ -40,27 +40,9 @@ export {
|
|
|
40
40
|
getCborValueByPath,
|
|
41
41
|
} from "@tari-project/tarijs-types";
|
|
42
42
|
export { IndexerProvider, IndexerProviderParameters } from "@tari-project/indexer-provider";
|
|
43
|
-
export
|
|
44
|
-
Amount,
|
|
45
|
-
BuiltInAccount,
|
|
46
|
-
VaultSubstate,
|
|
47
|
-
TransactionArg,
|
|
48
|
-
ConfidentialClaim,
|
|
49
|
-
ConfidentialOutput,
|
|
50
|
-
ConfidentialWithdrawProof,
|
|
51
|
-
SubstateType,
|
|
52
|
-
SimpleTransactionResult,
|
|
53
|
-
SimpleSubstateDiff,
|
|
54
|
-
AnySubstate,
|
|
55
|
-
DownSubstate,
|
|
56
|
-
UpSubstate,
|
|
57
|
-
TransactionSignature,
|
|
58
|
-
} from "@tari-project/tarijs-types";
|
|
43
|
+
export * from "@tari-project/tarijs-types";
|
|
59
44
|
|
|
60
45
|
import * as templates from "./templates";
|
|
61
46
|
import * as permissions from "@tari-project/tari-permissions";
|
|
62
47
|
|
|
63
|
-
export {
|
|
64
|
-
permissions,
|
|
65
|
-
templates,
|
|
66
|
-
};
|
|
48
|
+
export { permissions, templates };
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Amount,
|
|
3
|
+
ConfidentialWithdrawProof,
|
|
4
|
+
TariFunctionDefinition,
|
|
5
|
+
TariMethodDefinition,
|
|
6
|
+
} from "@tari-project/tarijs-builders";
|
|
2
7
|
import { TemplateFactory } from "./TemplateFactory";
|
|
3
8
|
|
|
4
9
|
interface MintFunction extends TariFunctionDefinition {
|
|
@@ -33,7 +38,7 @@ interface TakeFreeCoinsConfidentialMethod extends TariMethodDefinition {
|
|
|
33
38
|
|
|
34
39
|
interface BurnCoinsMethod extends TariMethodDefinition {
|
|
35
40
|
methodName: "burn_coins";
|
|
36
|
-
args?: [
|
|
41
|
+
args?: [bigint];
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
interface TotalSupplyMethod extends TariMethodDefinition {
|
|
@@ -108,7 +108,7 @@ describe("WalletDaemonTariSigner", () => {
|
|
|
108
108
|
|
|
109
109
|
const request: SubmitTransactionRequest = {
|
|
110
110
|
transaction: {
|
|
111
|
-
network:
|
|
111
|
+
network: NETWORK,
|
|
112
112
|
fee_instructions,
|
|
113
113
|
instructions: [],
|
|
114
114
|
inputs: [],
|
|
@@ -133,7 +133,7 @@ describe("WalletDaemonTariSigner", () => {
|
|
|
133
133
|
|
|
134
134
|
const request: SubmitTransactionRequest = {
|
|
135
135
|
transaction: {
|
|
136
|
-
network:
|
|
136
|
+
network: NETWORK,
|
|
137
137
|
fee_instructions: [],
|
|
138
138
|
instructions: [
|
|
139
139
|
{
|
|
@@ -233,10 +233,7 @@ describe("WalletDaemonTariSigner", () => {
|
|
|
233
233
|
.addInput({ substate_id: account.address, version: null })
|
|
234
234
|
.buildUnsignedTransaction();
|
|
235
235
|
|
|
236
|
-
const submitTransactionRequest = buildTransactionRequest(
|
|
237
|
-
transaction,
|
|
238
|
-
account.account_id,
|
|
239
|
-
);
|
|
236
|
+
const submitTransactionRequest = buildTransactionRequest(transaction, account.account_id);
|
|
240
237
|
|
|
241
238
|
const txResult = await submitAndWaitForTransaction(signer, submitTransactionRequest);
|
|
242
239
|
expect(txResult.status).toBe(TransactionStatus.Accepted);
|
|
@@ -254,9 +251,9 @@ describe("WalletDaemonTariSigner", () => {
|
|
|
254
251
|
|
|
255
252
|
assert(
|
|
256
253
|
accountBalances &&
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
254
|
+
typeof accountBalances === "object" &&
|
|
255
|
+
"balances" in accountBalances &&
|
|
256
|
+
accountBalances.balances,
|
|
260
257
|
"accountBalances is not an object",
|
|
261
258
|
);
|
|
262
259
|
assert(Array.isArray(accountBalances.balances), "accountBalances.balances is not an array");
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/tarijs-types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
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",
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export const ACCOUNT_TEMPLATE_ADDRESS = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
2
2
|
export const TARI_RESOURCE = "resource_0101010101010101010101010101010101010101010101010101010101010101";
|
|
3
|
-
export const XTR =
|
|
3
|
+
export const XTR = "resource_0101010101010101010101010101010101010101010101010101010101010101";
|
|
@@ -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.
|
|
3
|
+
"version": "0.13.0",
|
|
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
|
+
}
|
|
@@ -16,12 +16,16 @@ import {
|
|
|
16
16
|
ListSubstatesRequest,
|
|
17
17
|
} from "@tari-project/tarijs-types";
|
|
18
18
|
import {
|
|
19
|
+
AccountGetResponse,
|
|
20
|
+
AccountsListRequest,
|
|
21
|
+
AccountsListResponse,
|
|
19
22
|
ConfidentialViewVaultBalanceRequest,
|
|
20
23
|
KeyBranch,
|
|
21
24
|
ListAccountNftRequest,
|
|
22
25
|
ListAccountNftResponse,
|
|
23
26
|
substateIdToString,
|
|
24
27
|
SubstatesListRequest,
|
|
28
|
+
WalletGetInfoResponse,
|
|
25
29
|
} from "@tari-project/typescript-bindings";
|
|
26
30
|
|
|
27
31
|
export const WalletDaemonNotConnected = "WALLET_DAEMON_NOT_CONNECTED";
|
|
@@ -43,7 +47,6 @@ export interface WalletDaemonFetchParameters extends WalletDaemonBaseParameters
|
|
|
43
47
|
serverUrl: string;
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
|
|
47
50
|
export class WalletDaemonTariSigner implements TariSigner {
|
|
48
51
|
public signerName = "WalletDaemon";
|
|
49
52
|
params: WalletDaemonParameters;
|
|
@@ -56,7 +59,7 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
56
59
|
|
|
57
60
|
static async build(params: WalletDaemonParameters): Promise<WalletDaemonTariSigner> {
|
|
58
61
|
const allPermissions = WalletDaemonTariSigner.buildPermissions(params);
|
|
59
|
-
|
|
62
|
+
const connection = new TariConnection(params.signalingServerUrl, params.webRtcConfig);
|
|
60
63
|
const client = WalletDaemonClient.new(WebRtcRpcTransport.new(connection));
|
|
61
64
|
await connection.init(allPermissions, (conn) => {
|
|
62
65
|
params.onConnection?.();
|
|
@@ -134,7 +137,13 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
134
137
|
};
|
|
135
138
|
}
|
|
136
139
|
|
|
140
|
+
public async accountsList(req: AccountsListRequest): Promise<AccountsListResponse> {
|
|
141
|
+
const resp = await this.client.accountsList(req);
|
|
142
|
+
return resp;
|
|
143
|
+
}
|
|
144
|
+
|
|
137
145
|
public async getAccount(): Promise<AccountData> {
|
|
146
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
138
147
|
const { account, public_key } = (await this.client.accountsGetDefault({})) as any;
|
|
139
148
|
const address = typeof account.address === "object" ? account.address.Component : account.address;
|
|
140
149
|
const { balances } = await this.client.accountsGetBalances({
|
|
@@ -158,14 +167,21 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
158
167
|
};
|
|
159
168
|
}
|
|
160
169
|
|
|
170
|
+
public async getAccountByAddress(address: string): Promise<AccountGetResponse> {
|
|
171
|
+
const resp = await this.client.accountsGet({
|
|
172
|
+
name_or_address: {
|
|
173
|
+
ComponentAddress: address,
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
return resp;
|
|
177
|
+
}
|
|
178
|
+
|
|
161
179
|
public async getAccountBalances(componentAddress: string): Promise<unknown> {
|
|
162
180
|
return await this.client.accountsGetBalances({ account: { ComponentAddress: componentAddress }, refresh: true });
|
|
163
181
|
}
|
|
164
182
|
|
|
165
183
|
public async getSubstate(substateId: string): Promise<Substate> {
|
|
166
|
-
const {
|
|
167
|
-
substate,
|
|
168
|
-
} = await this.client.substatesGet({ substate_id: substateId });
|
|
184
|
+
const { substate } = await this.client.substatesGet({ substate_id: substateId });
|
|
169
185
|
if (!substate) {
|
|
170
186
|
throw new Error(`Substate not found for address: ${substateId}`);
|
|
171
187
|
}
|
|
@@ -212,16 +228,16 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
212
228
|
}
|
|
213
229
|
|
|
214
230
|
public async getTemplateDefinition(template_address: string): Promise<TemplateDefinition> {
|
|
215
|
-
|
|
231
|
+
const resp = await this.client.templatesGet({ template_address });
|
|
216
232
|
return resp.template_definition as TemplateDefinition;
|
|
217
233
|
}
|
|
218
234
|
|
|
219
235
|
public async getConfidentialVaultBalances({
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
236
|
+
vault_id,
|
|
237
|
+
view_key_id,
|
|
238
|
+
maximum_expected_value = null,
|
|
239
|
+
minimum_expected_value = null,
|
|
240
|
+
}: ConfidentialViewVaultBalanceRequest): Promise<VaultBalances> {
|
|
225
241
|
const res = await this.client.viewVaultBalance({
|
|
226
242
|
view_key_id,
|
|
227
243
|
vault_id,
|
|
@@ -232,11 +248,11 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
232
248
|
}
|
|
233
249
|
|
|
234
250
|
public async listSubstates({
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
251
|
+
filter_by_template,
|
|
252
|
+
filter_by_type,
|
|
253
|
+
limit,
|
|
254
|
+
offset,
|
|
255
|
+
}: ListSubstatesRequest): Promise<ListSubstatesResponse> {
|
|
240
256
|
const resp = await this.client.substatesList({
|
|
241
257
|
filter_by_template,
|
|
242
258
|
filter_by_type,
|
|
@@ -244,7 +260,7 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
244
260
|
offset,
|
|
245
261
|
} as SubstatesListRequest);
|
|
246
262
|
|
|
247
|
-
const substates = resp.substates.map((s) => ({
|
|
263
|
+
const substates = resp.substates.map((s: any) => ({
|
|
248
264
|
substate_id: typeof s.substate_id === "string" ? s.substate_id : substateIdToString(s.substate_id),
|
|
249
265
|
module_name: s.module_name,
|
|
250
266
|
version: s.version,
|
|
@@ -257,4 +273,9 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
257
273
|
public async getNftsList(req: ListAccountNftRequest): Promise<ListAccountNftResponse> {
|
|
258
274
|
return await this.client.nftsList(req);
|
|
259
275
|
}
|
|
276
|
+
|
|
277
|
+
public async getWalletInfo(): Promise<WalletGetInfoResponse> {
|
|
278
|
+
const resp = await this.client.walletGetInfo();
|
|
279
|
+
return resp;
|
|
280
|
+
}
|
|
260
281
|
}
|