@tari-project/tarijs 0.10.1 → 0.12.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/README.md +127 -67
- package/TODO.md +91 -3
- package/docusaurus/tari-docs/README.md +200 -17
- package/docusaurus/tari-docs/docs/api-reference.md +665 -0
- package/docusaurus/tari-docs/docs/contributing.md +619 -0
- package/docusaurus/tari-docs/docs/guides/getting-started-tutorial.md +965 -0
- package/docusaurus/tari-docs/docs/guides/production-deployment.md +977 -0
- package/docusaurus/tari-docs/docs/index.md +114 -11
- package/docusaurus/tari-docs/docs/installation.md +142 -1
- package/docusaurus/tari-docs/docs/signers/metamask.md +529 -0
- package/docusaurus/tari-docs/docs/troubleshooting.md +661 -0
- package/docusaurus/tari-docs/package.json +4 -4
- package/eslint.config.mjs +9 -0
- package/examples/vite-typescript-react/README.md +9 -0
- package/examples/vite-typescript-react/eslint.config.js +23 -0
- package/examples/vite-typescript-react/index.html +13 -0
- package/examples/vite-typescript-react/package.json +35 -0
- package/examples/vite-typescript-react/public/vite.svg +1 -0
- package/examples/vite-typescript-react/src/App.css +42 -0
- package/examples/vite-typescript-react/src/App.tsx +50 -0
- package/examples/vite-typescript-react/src/assets/react.svg +1 -0
- package/examples/vite-typescript-react/src/index.css +68 -0
- package/examples/vite-typescript-react/src/main.tsx +10 -0
- package/examples/vite-typescript-react/src/vite-env.d.ts +1 -0
- package/examples/vite-typescript-react/tsconfig.app.json +27 -0
- package/examples/vite-typescript-react/tsconfig.json +7 -0
- package/examples/vite-typescript-react/tsconfig.node.json +25 -0
- package/examples/vite-typescript-react/vite.config.ts +7 -0
- package/package.json +16 -3
- package/packages/builders/package.json +2 -2
- package/packages/builders/src/helpers/submitTransaction.ts +10 -35
- package/packages/builders/src/transaction/TransactionBuilder.ts +227 -29
- package/packages/indexer_provider/package.json +2 -2
- package/packages/indexer_provider/src/provider.ts +5 -5
- package/packages/indexer_provider/tsconfig.json +4 -2
- package/packages/metamask_signer/package.json +2 -2
- package/packages/metamask_signer/src/index.ts +3 -15
- package/packages/{tari_permissions → permissions}/package.json +2 -2
- package/packages/{tari_permissions → permissions}/src/helpers.ts +1 -1
- package/packages/permissions/src/index.ts +2 -0
- package/packages/{tari_permissions/src/tari_permissions.ts → permissions/src/permissions.ts} +56 -6
- package/packages/react-mui-connect-button/moon.yml +71 -0
- package/packages/react-mui-connect-button/package.json +40 -0
- package/packages/react-mui-connect-button/src/Logos.tsx +60 -0
- package/packages/react-mui-connect-button/src/TariConnectButton.tsx +51 -0
- package/packages/react-mui-connect-button/src/TariWalletSelectionDialog.tsx +116 -0
- package/packages/react-mui-connect-button/src/content/tari-logo-white.svg +18 -0
- package/packages/react-mui-connect-button/src/content/tari-logo.svg +18 -0
- package/packages/react-mui-connect-button/src/content/walletconnect-logo.svg +13 -0
- package/packages/react-mui-connect-button/src/defaultPermissions.ts +0 -0
- package/packages/react-mui-connect-button/src/index.ts +24 -0
- package/packages/react-mui-connect-button/tsconfig.json +31 -0
- package/packages/tari_provider/package.json +2 -2
- package/packages/tari_provider/src/TariProvider.ts +6 -1
- package/packages/tari_signer/package.json +2 -2
- package/packages/tari_universe/package.json +2 -2
- package/packages/tari_universe/tsconfig.json +4 -2
- package/packages/tarijs/package.json +2 -2
- package/packages/tarijs/src/index.ts +27 -49
- package/packages/tarijs/src/templates/Account.ts +7 -4
- package/packages/tarijs/test/integration-tests/.env +1 -1
- package/packages/tarijs/test/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +112 -73
- package/packages/tarijs/tsconfig.json +6 -4
- package/packages/tarijs/vitest.config.ts +2 -1
- package/packages/tarijs_types/package.json +4 -3
- package/packages/tarijs_types/src/Account.ts +68 -0
- package/packages/tarijs_types/src/Amount.ts +5 -1
- package/packages/tarijs_types/src/TransactionResult.ts +1 -8
- package/packages/tarijs_types/src/consts.ts +3 -0
- package/packages/tarijs_types/src/helpers/index.ts +4 -0
- package/packages/tarijs_types/src/helpers/simpleResult.ts +345 -0
- package/packages/tarijs_types/src/helpers/txResult.ts +1 -2
- package/packages/tarijs_types/src/index.ts +8 -0
- package/packages/tarijs_types/src/signer.ts +1 -1
- package/packages/wallet_daemon/package.json +2 -2
- package/packages/wallet_daemon/src/provider.ts +8 -6
- package/packages/wallet_daemon/src/signer.ts +18 -8
- package/packages/wallet_daemon/tsconfig.json +1 -1
- package/packages/walletconnect/package.json +3 -2
- package/packages/walletconnect/src/index.ts +54 -28
- package/packages/walletconnect/tsconfig.json +3 -0
- package/pnpm-workspace.yaml +15 -7
- package/scripts/check_versions.sh +4 -0
- package/scripts/clean_everything.sh +38 -0
- package/tsconfig.json +6 -0
- package/typedoc.json +10 -0
- package/packages/tari_permissions/src/index.ts +0 -2
- /package/packages/{tari_permissions → permissions}/moon.yml +0 -0
- /package/packages/{tari_permissions → permissions}/tsconfig.json +0 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { BigAmount, ResourceAddress, ResourceType, Vault, VaultId } from "@tari-project/typescript-bindings";
|
|
2
|
+
|
|
3
|
+
export interface BuiltInAccount {
|
|
4
|
+
vaults: Record<ResourceAddress, VaultSubstate>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class VaultSubstate {
|
|
8
|
+
private vaultId: VaultId;
|
|
9
|
+
private vault: Vault;
|
|
10
|
+
|
|
11
|
+
constructor(vaultId: VaultId, vault: Vault) {
|
|
12
|
+
this.vaultId = vaultId;
|
|
13
|
+
this.vault = vault;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public static new(vaultId: VaultId, vault: Vault): VaultSubstate {
|
|
17
|
+
return new VaultSubstate(vaultId, vault);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public get id(): VaultId {
|
|
21
|
+
return this.vaultId;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public get rawVault(): Vault {
|
|
25
|
+
return this.vault;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public get resourceType(): ResourceType {
|
|
29
|
+
if ("Fungible" in this.vault.resource_container) {
|
|
30
|
+
return "Fungible";
|
|
31
|
+
}
|
|
32
|
+
if ("NonFungible" in this.vault.resource_container) {
|
|
33
|
+
return "NonFungible";
|
|
34
|
+
}
|
|
35
|
+
if ("Confidential" in this.vault.resource_container) {
|
|
36
|
+
return "Confidential";
|
|
37
|
+
}
|
|
38
|
+
throw new Error("Unknown resource type in vault");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public get balance(): BigAmount {
|
|
42
|
+
if ("Fungible" in this.vault.resource_container) {
|
|
43
|
+
return BigAmount.from(this.vault.resource_container.Fungible.amount);
|
|
44
|
+
}
|
|
45
|
+
if ("NonFungible" in this.vault.resource_container) {
|
|
46
|
+
return BigAmount.from(this.vault.resource_container.NonFungible.token_ids.length);
|
|
47
|
+
}
|
|
48
|
+
if ("Confidential" in this.vault.resource_container) {
|
|
49
|
+
return BigAmount.from(this.vault.resource_container.Confidential.revealed_amount);
|
|
50
|
+
}
|
|
51
|
+
throw new Error("Unknown resource type in vault");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public get resourceAddress(): ResourceAddress {
|
|
55
|
+
if ("Fungible" in this.vault.resource_container) {
|
|
56
|
+
return this.vault.resource_container.Fungible.address;
|
|
57
|
+
}
|
|
58
|
+
if ("NonFungible" in this.vault.resource_container) {
|
|
59
|
+
return this.vault.resource_container.NonFungible.address;
|
|
60
|
+
}
|
|
61
|
+
if ("Confidential" in this.vault.resource_container) {
|
|
62
|
+
return this.vault.resource_container.Confidential.address;
|
|
63
|
+
}
|
|
64
|
+
throw new Error("Unknown resource type in vault");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// TODO: add other quality of life helpers e.g balances
|
|
68
|
+
}
|
|
@@ -7,7 +7,7 @@ export class Amount {
|
|
|
7
7
|
|
|
8
8
|
public static readonly MAX: Amount = new Amount(Number.MAX_SAFE_INTEGER);
|
|
9
9
|
|
|
10
|
-
public static
|
|
10
|
+
public static new(amount: number): Amount {
|
|
11
11
|
return new Amount(amount);
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -110,4 +110,8 @@ export class Amount {
|
|
|
110
110
|
}
|
|
111
111
|
return this.value as number;
|
|
112
112
|
}
|
|
113
|
+
|
|
114
|
+
public toJSON(): number {
|
|
115
|
+
return this.value;
|
|
116
|
+
}
|
|
113
117
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { TransactionStatus } from "./TransactionStatus";
|
|
2
1
|
import { DownSubstates, UpSubstates } from "./SubstateDiff";
|
|
3
|
-
import { ComponentAddress,
|
|
2
|
+
import { ComponentAddress, TransactionResult } from "@tari-project/typescript-bindings";
|
|
4
3
|
|
|
5
4
|
export type SubmitTransactionResponse = {
|
|
6
5
|
transaction_id: string;
|
|
@@ -15,9 +14,3 @@ export interface SubmitTxResult {
|
|
|
15
14
|
|
|
16
15
|
getComponentForTemplate(templateAddress: string): ComponentAddress | null;
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
export type TransactionResultResponse = {
|
|
20
|
-
transaction_id: string;
|
|
21
|
-
status: TransactionStatus;
|
|
22
|
-
result: FinalizeResult | null;
|
|
23
|
-
};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { NonFungibleId, NonFungibleToken, ResourceAddress } from "@tari-project/typescript-bindings";
|
|
2
2
|
import { TransactionStatus } from "../TransactionStatus";
|
|
3
|
+
|
|
3
4
|
export { fromHexString, toHexString } from "./hexString";
|
|
4
5
|
export { txResultCheck, getSubstateValueFromUpSubstates, getComponentsForTemplate } from "./txResult";
|
|
5
6
|
export { BinaryTag, CborValue, convertTaggedValue, getCborValueByPath, parseCbor } from "./cbor";
|
|
7
|
+
export {
|
|
8
|
+
SimpleSubstateDiff, SimpleTransactionResult, AnySubstate, UpSubstate, DownSubstate, splitOnce,
|
|
9
|
+
} from "./simpleResult";
|
|
6
10
|
export {
|
|
7
11
|
substateIdToString,
|
|
8
12
|
stringToSubstateId,
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Vault,
|
|
3
|
+
SubstateId,
|
|
4
|
+
substateIdToString,
|
|
5
|
+
ComponentHeader,
|
|
6
|
+
NonFungible,
|
|
7
|
+
RejectReason,
|
|
8
|
+
Resource,
|
|
9
|
+
Substate,
|
|
10
|
+
SubstateDiff,
|
|
11
|
+
SubstateType,
|
|
12
|
+
TransactionReceipt,
|
|
13
|
+
UnclaimedConfidentialOutput,
|
|
14
|
+
ValidatorFeePool,
|
|
15
|
+
PublishedTemplate,
|
|
16
|
+
ValidatorFeeWithdrawal,
|
|
17
|
+
PublishedTemplateAddress,
|
|
18
|
+
TransactionId,
|
|
19
|
+
FinalizeResult,
|
|
20
|
+
LogEntry,
|
|
21
|
+
Event,
|
|
22
|
+
} from "@tari-project/typescript-bindings";
|
|
23
|
+
import { VaultSubstate, BuiltInAccount } from "../Account";
|
|
24
|
+
import { TransactionStatus } from "../TransactionStatus";
|
|
25
|
+
import { Option, Some, None } from "@thames/monads";
|
|
26
|
+
import { GetTransactionResultResponse } from "../GetTransactionResultResponse";
|
|
27
|
+
import { parseCbor } from "../";
|
|
28
|
+
import { ACCOUNT_TEMPLATE_ADDRESS } from "../consts";
|
|
29
|
+
|
|
30
|
+
export class SimpleTransactionResult {
|
|
31
|
+
private readonly transaction_id: TransactionId;
|
|
32
|
+
private readonly finalizeResult: FinalizeResult;
|
|
33
|
+
private readonly _status: TransactionStatus;
|
|
34
|
+
|
|
35
|
+
constructor(transaction_id: TransactionId, status: TransactionStatus, result: FinalizeResult) {
|
|
36
|
+
this.transaction_id = transaction_id;
|
|
37
|
+
this._status = status;
|
|
38
|
+
this.finalizeResult = result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static new(transaction_id: TransactionId, status: TransactionStatus, result: FinalizeResult): SimpleTransactionResult {
|
|
42
|
+
return new SimpleTransactionResult(transaction_id, status, result);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static fromResponse(resp: GetTransactionResultResponse): SimpleTransactionResult {
|
|
46
|
+
if (!resp.result) {
|
|
47
|
+
throw new Error("Transaction result is missing in the response");
|
|
48
|
+
}
|
|
49
|
+
return SimpleTransactionResult.new(resp.transaction_id, resp.status, resp.result);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public get transactionId(): string {
|
|
53
|
+
return this.transaction_id;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public get result(): FinalizeResult {
|
|
57
|
+
return this.finalizeResult;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public get status(): TransactionStatus {
|
|
61
|
+
return this._status;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public get logs(): LogEntry[] {
|
|
65
|
+
return this.result.logs;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public get events(): Event[] {
|
|
69
|
+
return this.result.events;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public getResultingComponents(): ComponentHeader[] {
|
|
73
|
+
return this.getNewSubstatesOfType("Component") as ComponentHeader[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public getResultingResources(): Resource[] {
|
|
77
|
+
return this.getNewSubstatesOfType("Resource") as Resource[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public getResultingVaults(): VaultSubstate[] {
|
|
81
|
+
const vaults = this.getUpSubstatesOfType("Vault");
|
|
82
|
+
return vaults.map((upSubstate) => VaultSubstate.new(upSubstate.id, upSubstate.substate as Vault));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public getResultingNonFungibles(): NonFungible[] {
|
|
86
|
+
return this.getNewSubstatesOfType("NonFungible") as NonFungible[];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public getTransactionReceipt(): TransactionReceipt {
|
|
90
|
+
return this.getNewSubstatesOfType("TransactionReceipt")[0]! as TransactionReceipt;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public getNewPublishedTemplates(): PublishedTemplate[] {
|
|
94
|
+
return this.getNewSubstatesOfType("Template") as PublishedTemplate[];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public getNewSubstatesOfType(type: SubstateType): AnySubstate[] {
|
|
98
|
+
const upSubstates = this.getUpSubstatesOfType(type);
|
|
99
|
+
return upSubstates.map((upSubstate) => upSubstate.substate);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public getUpSubstatesOfType(type: SubstateType): UpSubstate[] {
|
|
103
|
+
const diff = this.diff;
|
|
104
|
+
if (diff.isNone()) {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
const d = diff.unwrap();
|
|
108
|
+
|
|
109
|
+
const substates = [];
|
|
110
|
+
for (const upSubstate of d.upSubstates()) {
|
|
111
|
+
if (upSubstate.type === type) {
|
|
112
|
+
substates.push(upSubstate);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return substates;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public getComponentsByTemplateAddress(templateAddress: PublishedTemplateAddress): SimpleComponent[] {
|
|
120
|
+
const diff = this.diff;
|
|
121
|
+
if (diff.isNone()) {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
const d = diff.unwrap();
|
|
125
|
+
|
|
126
|
+
const components = [];
|
|
127
|
+
for (const upSubstate of d.upSubstates()) {
|
|
128
|
+
if (upSubstate.type === "Component" && (upSubstate.substate as ComponentHeader).template_address === templateAddress) {
|
|
129
|
+
components.push(SimpleComponent.new(upSubstate.id, upSubstate.version, upSubstate.substate as ComponentHeader));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return components;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public getResultingAccounts(): GetAccountsResult[] {
|
|
137
|
+
const components = this.getComponentsByTemplateAddress(ACCOUNT_TEMPLATE_ADDRESS);
|
|
138
|
+
|
|
139
|
+
const accounts = [];
|
|
140
|
+
for (const component of components) {
|
|
141
|
+
const account = component.decodeBody<BuiltInAccount>();
|
|
142
|
+
accounts.push({ substate_id: component.id, version: component.version, account });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return accounts;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Returns the reject reason if the whole transaction was rejected or if the fee intent was executed but the main intent rejected
|
|
150
|
+
* Otherwise returns None.
|
|
151
|
+
*/
|
|
152
|
+
public get anyRejectReason(): Option<RejectReason> {
|
|
153
|
+
return this.rejected.or(this.onlyFeeAccepted.map((x) => x[1]));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public get accept(): Option<SimpleSubstateDiff> {
|
|
157
|
+
const result = this.result as any;
|
|
158
|
+
const accept = result?.result.Accept;
|
|
159
|
+
if (!accept) {
|
|
160
|
+
return None;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return Some(SimpleSubstateDiff.from(accept));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public get diff(): Option<SimpleSubstateDiff> {
|
|
167
|
+
return this.accept.or(this.onlyFeeAccepted.map((x => x[0])));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public get onlyFeeAccepted(): Option<[SimpleSubstateDiff, RejectReason]> {
|
|
171
|
+
const result = this.result;
|
|
172
|
+
if (!result || !result.result || !("AcceptFeeRejectRest" in result.result)) {
|
|
173
|
+
return None;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const [diff, reason] = result?.result.AcceptFeeRejectRest;
|
|
177
|
+
return Some([SimpleSubstateDiff.from(diff), reason]);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public get rejected(): Option<RejectReason> {
|
|
181
|
+
const result = this.result as any;
|
|
182
|
+
if (!result || !result.result) {
|
|
183
|
+
return None;
|
|
184
|
+
}
|
|
185
|
+
if (!("Reject" in result.result)) {
|
|
186
|
+
return None;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return Some(result?.result.Reject);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function splitOnce(str: string, separator: string): [string, string] | null {
|
|
194
|
+
const index = str.indexOf(separator);
|
|
195
|
+
if (index === -1) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
return [str.slice(0, index), str.slice(index + separator.length)];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function prefixToSubstateType(prefix: string): SubstateType | null {
|
|
202
|
+
switch (prefix) {
|
|
203
|
+
case "component":
|
|
204
|
+
return "Component";
|
|
205
|
+
case "resource":
|
|
206
|
+
return "Resource";
|
|
207
|
+
case "vault":
|
|
208
|
+
return "Vault";
|
|
209
|
+
case "nft":
|
|
210
|
+
return "NonFungible";
|
|
211
|
+
case "txreceipt":
|
|
212
|
+
return "TransactionReceipt";
|
|
213
|
+
case "vnfp":
|
|
214
|
+
return "ValidatorFeePool";
|
|
215
|
+
case "template":
|
|
216
|
+
return "Template";
|
|
217
|
+
default:
|
|
218
|
+
console.log("Unknown substate type prefix", prefix);
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export class SimpleSubstateDiff {
|
|
224
|
+
private up_substates: UpSubstate[];
|
|
225
|
+
private down_substates: DownSubstate[];
|
|
226
|
+
private fee_withdrawals: ValidatorFeeWithdrawal[];
|
|
227
|
+
|
|
228
|
+
constructor(diff: SubstateDiff) {
|
|
229
|
+
this.up_substates = diff.up_substates
|
|
230
|
+
.map(([id, val]: [SubstateId | string, Substate]) => {
|
|
231
|
+
|
|
232
|
+
if (!val.substate) {
|
|
233
|
+
console.error("Substate is missing in the accept result", id, val);
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const valType = Object.keys(val.substate)[0];
|
|
238
|
+
if (!valType) {
|
|
239
|
+
console.log("Substate is missing key", id, val);
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
const idVal = (typeof id === "string" ? id : Object.values(id)[0]) as string;
|
|
243
|
+
return {
|
|
244
|
+
type: valType,
|
|
245
|
+
id: idVal,
|
|
246
|
+
version: val.version,
|
|
247
|
+
// @ts-ignore
|
|
248
|
+
substate: val.substate[valType],
|
|
249
|
+
} as UpSubstate;
|
|
250
|
+
})
|
|
251
|
+
.filter((x) => x !== null);
|
|
252
|
+
|
|
253
|
+
this.down_substates = diff.down_substates
|
|
254
|
+
.map(([id, version]: [SubstateId | string, number]) => {
|
|
255
|
+
const type = (typeof id === "string" ? prefixToSubstateType(splitOnce(id, "_")![0]) : Object.keys(id)[0]);
|
|
256
|
+
const idVal = substateIdToString(id);
|
|
257
|
+
return {
|
|
258
|
+
type: type! as SubstateType,
|
|
259
|
+
id: idVal,
|
|
260
|
+
version,
|
|
261
|
+
} as DownSubstate;
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
this.fee_withdrawals = diff.fee_withdrawals;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
public static from(diff: SubstateDiff): SimpleSubstateDiff {
|
|
269
|
+
return new SimpleSubstateDiff(diff);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
public upSubstates(): UpSubstate[] {
|
|
273
|
+
return this.up_substates;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
public downSubstates(): DownSubstate[] {
|
|
277
|
+
return this.down_substates;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public feeWithdrawals(): ValidatorFeeWithdrawal[] {
|
|
281
|
+
return this.fee_withdrawals;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export type AnySubstate =
|
|
286
|
+
ComponentHeader
|
|
287
|
+
| Resource
|
|
288
|
+
| Vault
|
|
289
|
+
| UnclaimedConfidentialOutput
|
|
290
|
+
| NonFungible
|
|
291
|
+
| TransactionReceipt
|
|
292
|
+
| ValidatorFeePool
|
|
293
|
+
| PublishedTemplate;
|
|
294
|
+
|
|
295
|
+
export type UpSubstate = {
|
|
296
|
+
type: SubstateType;
|
|
297
|
+
id: string;
|
|
298
|
+
version: number;
|
|
299
|
+
substate: AnySubstate
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
export type DownSubstate = {
|
|
303
|
+
type: SubstateType;
|
|
304
|
+
id: string;
|
|
305
|
+
version: number;
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
export class SimpleComponent {
|
|
309
|
+
private _id: string;
|
|
310
|
+
private _version: number;
|
|
311
|
+
private _substate: ComponentHeader;
|
|
312
|
+
|
|
313
|
+
constructor(id: string, version: number, substate: ComponentHeader) {
|
|
314
|
+
this._id = id;
|
|
315
|
+
this._version = version;
|
|
316
|
+
this._substate = substate;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
public static new(id: string, version: number, substate: ComponentHeader): SimpleComponent {
|
|
320
|
+
return new SimpleComponent(id, version, substate);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
public get id(): string {
|
|
324
|
+
return this._id;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
public get version(): number {
|
|
328
|
+
return this._version;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
public get substate(): ComponentHeader {
|
|
332
|
+
return this._substate;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
public decodeBody<T>(): T {
|
|
336
|
+
return parseCbor(this.substate.body.state) as T;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
export interface GetAccountsResult {
|
|
342
|
+
substate_id: string;
|
|
343
|
+
version: number;
|
|
344
|
+
account: BuiltInAccount;
|
|
345
|
+
}
|
|
@@ -59,11 +59,10 @@ export function getSubstateValueFromUpSubstates(
|
|
|
59
59
|
|
|
60
60
|
export function getComponentsForTemplate(templateAddress: string, upSubstates: UpSubstates): ComponentAddress[] | null {
|
|
61
61
|
const components: ComponentAddress[] = [];
|
|
62
|
-
const templateAddressBytes = new TextEncoder().encode(templateAddress);
|
|
63
62
|
for (const [substateId, substate] of upSubstates) {
|
|
64
63
|
if ("Component" in substate.substate) {
|
|
65
64
|
const componentHeader = substate.substate.Component;
|
|
66
|
-
if (componentHeader.template_address ===
|
|
65
|
+
if (componentHeader.template_address === templateAddress) {
|
|
67
66
|
components.push(substateIdToString(substateId));
|
|
68
67
|
}
|
|
69
68
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { ComponentAddress, ResourceAddress, PublishedTemplateAddress, Epoch } from "@tari-project/typescript-bindings";
|
|
2
2
|
export { Amount } from "./Amount";
|
|
3
|
+
export { BuiltInAccount, VaultSubstate } from "./Account";
|
|
3
4
|
export { TransactionArg } from "./TransactionArg";
|
|
4
5
|
export { ConfidentialClaim } from "./ConfidentialClaim";
|
|
5
6
|
export { ConfidentialOutput } from "./ConfidentialOutput";
|
|
@@ -53,4 +54,11 @@ export {
|
|
|
53
54
|
txResultCheck,
|
|
54
55
|
BinaryTag,
|
|
55
56
|
CborValue,
|
|
57
|
+
SimpleTransactionResult,
|
|
58
|
+
SimpleSubstateDiff,
|
|
59
|
+
AnySubstate,
|
|
60
|
+
DownSubstate,
|
|
61
|
+
UpSubstate,
|
|
62
|
+
splitOnce,
|
|
56
63
|
} from "./helpers";
|
|
64
|
+
export { ACCOUNT_TEMPLATE_ADDRESS, XTR, TARI_RESOURCE } from "./consts";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/wallet-daemon-signer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"build": "tsc -b"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [],
|
|
13
|
-
"author": "",
|
|
13
|
+
"author": "The Tari Community",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@tari-project/tari-permissions": "workspace:^",
|
|
@@ -76,15 +76,17 @@ export class WalletDaemonTariProvider implements TariProvider {
|
|
|
76
76
|
async getSubstate(req: GetSubstateRequest): Promise<Substate> {
|
|
77
77
|
// TODO: Substate address cannot be converted to SubstateId directly - Perhaps we need to change the provider interface
|
|
78
78
|
const {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
substate,
|
|
80
|
+
} = await this.client.substatesGet({ substate_id: req.substate_address });
|
|
81
|
+
if (!substate) {
|
|
82
|
+
throw new Error(`Substate not found for address: ${req.substate_address}`);
|
|
83
|
+
}
|
|
82
84
|
|
|
83
85
|
return {
|
|
84
|
-
value,
|
|
86
|
+
value: substate?.substate,
|
|
85
87
|
address: {
|
|
86
|
-
substate_id:
|
|
87
|
-
version:
|
|
88
|
+
substate_id: req.substate_address,
|
|
89
|
+
version: substate?.version || 0,
|
|
88
90
|
},
|
|
89
91
|
};
|
|
90
92
|
}
|
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
KeyBranch,
|
|
21
21
|
ListAccountNftRequest,
|
|
22
22
|
ListAccountNftResponse,
|
|
23
|
-
SubstateId,
|
|
24
23
|
substateIdToString,
|
|
25
24
|
SubstatesListRequest,
|
|
26
25
|
} from "@tari-project/typescript-bindings";
|
|
@@ -44,6 +43,7 @@ export interface WalletDaemonFetchParameters extends WalletDaemonBaseParameters
|
|
|
44
43
|
serverUrl: string;
|
|
45
44
|
}
|
|
46
45
|
|
|
46
|
+
|
|
47
47
|
export class WalletDaemonTariSigner implements TariSigner {
|
|
48
48
|
public signerName = "WalletDaemon";
|
|
49
49
|
params: WalletDaemonParameters;
|
|
@@ -93,6 +93,11 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
93
93
|
return transport instanceof WebRtcRpcTransport ? transport : undefined;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
public async newTransactionKey(index?: number): Promise<string> {
|
|
97
|
+
const resp = await this.client.createKey({ branch: "transaction", specific_index: index || null });
|
|
98
|
+
return resp.public_key;
|
|
99
|
+
}
|
|
100
|
+
|
|
96
101
|
public get token(): string | undefined {
|
|
97
102
|
return this.getWebRtcTransport()?.token();
|
|
98
103
|
}
|
|
@@ -125,7 +130,7 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
125
130
|
account_id: res.account.key_index,
|
|
126
131
|
address: (res.account.address as { Component: string }).Component,
|
|
127
132
|
public_key: res.public_key,
|
|
128
|
-
|
|
133
|
+
vaults: [],
|
|
129
134
|
};
|
|
130
135
|
}
|
|
131
136
|
|
|
@@ -142,7 +147,7 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
142
147
|
address,
|
|
143
148
|
public_key,
|
|
144
149
|
// TODO: should be vaults not resources
|
|
145
|
-
|
|
150
|
+
vaults: balances.map((b: any) => ({
|
|
146
151
|
type: b.resource_type,
|
|
147
152
|
resource_address: b.resource_address,
|
|
148
153
|
balance: b.balance + b.confidential_balance,
|
|
@@ -158,13 +163,18 @@ export class WalletDaemonTariSigner implements TariSigner {
|
|
|
158
163
|
}
|
|
159
164
|
|
|
160
165
|
public async getSubstate(substateId: string): Promise<Substate> {
|
|
161
|
-
|
|
162
|
-
|
|
166
|
+
const {
|
|
167
|
+
substate,
|
|
168
|
+
} = await this.client.substatesGet({ substate_id: substateId });
|
|
169
|
+
if (!substate) {
|
|
170
|
+
throw new Error(`Substate not found for address: ${substateId}`);
|
|
171
|
+
}
|
|
172
|
+
|
|
163
173
|
return {
|
|
164
|
-
value,
|
|
174
|
+
value: substate?.substate,
|
|
165
175
|
address: {
|
|
166
|
-
substate_id:
|
|
167
|
-
version:
|
|
176
|
+
substate_id: substateId,
|
|
177
|
+
version: substate?.version || 0,
|
|
168
178
|
},
|
|
169
179
|
};
|
|
170
180
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/wallet-connect-signer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"build": "tsc -b"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [],
|
|
13
|
-
"author": "",
|
|
13
|
+
"author": "The Tari Community",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@tari-project/tari-signer": "workspace:^",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"@tari-project/tarijs-types": "workspace:^",
|
|
19
19
|
"@tari-project/typescript-bindings": "catalog:",
|
|
20
20
|
"@tari-project/wallet_jrpc_client": "catalog:",
|
|
21
|
+
"@tari-project/tari-permissions": "workspace:",
|
|
21
22
|
"@walletconnect/modal": "catalog:",
|
|
22
23
|
"@walletconnect/universal-provider": "catalog:"
|
|
23
24
|
},
|