@tari-project/tarijs 0.1.21 → 0.1.22

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.
Files changed (109) hide show
  1. package/dist/builders/helpers/index.d.ts +2 -0
  2. package/dist/builders/helpers/index.js +2 -0
  3. package/dist/builders/helpers/submitTransaction.d.ts +13 -0
  4. package/dist/builders/helpers/submitTransaction.js +59 -0
  5. package/dist/builders/helpers/workspace.d.ts +23 -0
  6. package/dist/builders/helpers/workspace.js +29 -0
  7. package/dist/builders/index.d.ts +3 -0
  8. package/dist/builders/index.js +3 -0
  9. package/dist/builders/transaction/TransactionBuilder.d.ts +44 -0
  10. package/dist/builders/transaction/TransactionBuilder.js +164 -0
  11. package/dist/builders/transaction/TransactionRequest.d.ts +27 -0
  12. package/dist/builders/transaction/TransactionRequest.js +67 -0
  13. package/dist/builders/transaction/index.d.ts +2 -0
  14. package/dist/builders/transaction/index.js +2 -0
  15. package/dist/builders/types/Amount.d.ts +23 -0
  16. package/dist/builders/types/Amount.js +93 -0
  17. package/dist/builders/types/Arg.d.ts +1 -0
  18. package/dist/builders/types/Arg.js +1 -0
  19. package/dist/builders/types/Builder.d.ts +47 -0
  20. package/dist/builders/types/Builder.js +1 -0
  21. package/dist/builders/types/ComponentAddress.d.ts +1 -0
  22. package/dist/builders/types/ComponentAddress.js +1 -0
  23. package/dist/builders/types/ConfidentialClaim.d.ts +8 -0
  24. package/dist/builders/types/ConfidentialClaim.js +1 -0
  25. package/dist/builders/types/ConfidentialOutput.d.ts +8 -0
  26. package/dist/builders/types/ConfidentialOutput.js +1 -0
  27. package/dist/builders/types/ConfidentialOutputStatement.d.ts +9 -0
  28. package/dist/builders/types/ConfidentialOutputStatement.js +1 -0
  29. package/dist/builders/types/ConfidentialStatement.d.ts +8 -0
  30. package/dist/builders/types/ConfidentialStatement.js +1 -0
  31. package/dist/builders/types/ConfidentialWithdrawProof.d.ts +7 -0
  32. package/dist/builders/types/ConfidentialWithdrawProof.js +1 -0
  33. package/dist/builders/types/ElgamalVerifiableBalance.d.ts +4 -0
  34. package/dist/builders/types/ElgamalVerifiableBalance.js +1 -0
  35. package/dist/builders/types/Epoch.d.ts +1 -0
  36. package/dist/builders/types/Epoch.js +1 -0
  37. package/dist/builders/types/FinalizeResult.d.ts +20 -0
  38. package/dist/builders/types/FinalizeResult.js +1 -0
  39. package/dist/builders/types/Instruction.d.ts +56 -0
  40. package/dist/builders/types/Instruction.js +1 -0
  41. package/dist/builders/types/ResourceAddress.d.ts +1 -0
  42. package/dist/builders/types/ResourceAddress.js +2 -0
  43. package/dist/builders/types/SubstateDiff.d.ts +7 -0
  44. package/dist/builders/types/SubstateDiff.js +1 -0
  45. package/dist/builders/types/SubstateRequirement.d.ts +5 -0
  46. package/dist/builders/types/SubstateRequirement.js +1 -0
  47. package/dist/builders/types/TemplateAddress.d.ts +1 -0
  48. package/dist/builders/types/TemplateAddress.js +2 -0
  49. package/dist/builders/types/Transaction.d.ts +15 -0
  50. package/dist/builders/types/Transaction.js +1 -0
  51. package/dist/builders/types/TransactionId.d.ts +1 -0
  52. package/dist/builders/types/TransactionId.js +1 -0
  53. package/dist/builders/types/TransactionResult.d.ts +22 -0
  54. package/dist/builders/types/TransactionResult.js +10 -0
  55. package/dist/builders/types/TransactionSignature.d.ts +4 -0
  56. package/dist/builders/types/TransactionSignature.js +1 -0
  57. package/dist/builders/types/UnsignedTransaction.d.ts +12 -0
  58. package/dist/builders/types/UnsignedTransaction.js +1 -0
  59. package/dist/builders/types/VersionedSubstateId.d.ts +5 -0
  60. package/dist/builders/types/VersionedSubstateId.js +1 -0
  61. package/dist/builders/types/ViewableBalanceProof.d.ts +10 -0
  62. package/dist/builders/types/ViewableBalanceProof.js +2 -0
  63. package/dist/builders/types/Workspace.d.ts +3 -0
  64. package/dist/builders/types/Workspace.js +1 -0
  65. package/dist/builders/types/index.d.ts +24 -0
  66. package/dist/builders/types/index.js +2 -0
  67. package/dist/index.d.ts +13 -0
  68. package/dist/index.js +12 -0
  69. package/dist/providers/index.d.ts +16 -0
  70. package/dist/providers/index.js +1 -0
  71. package/dist/providers/metamask/index.d.ts +30 -0
  72. package/dist/providers/metamask/index.js +169 -0
  73. package/dist/providers/metamask/utils.d.ts +38 -0
  74. package/dist/providers/metamask/utils.js +55 -0
  75. package/dist/providers/tari_universe/index.d.ts +3 -0
  76. package/dist/providers/tari_universe/index.js +3 -0
  77. package/dist/providers/tari_universe/provider.d.ts +23 -0
  78. package/dist/providers/tari_universe/provider.js +88 -0
  79. package/dist/providers/tari_universe/types.d.ts +30 -0
  80. package/dist/providers/tari_universe/types.js +1 -0
  81. package/dist/providers/types.d.ts +66 -0
  82. package/dist/providers/types.js +10 -0
  83. package/dist/providers/wallet_daemon/index.d.ts +3 -0
  84. package/dist/providers/wallet_daemon/index.js +3 -0
  85. package/dist/providers/wallet_daemon/provider.d.ts +35 -0
  86. package/dist/providers/wallet_daemon/provider.js +173 -0
  87. package/dist/providers/wallet_daemon/tari_permissions.d.ts +216 -0
  88. package/dist/providers/wallet_daemon/tari_permissions.js +282 -0
  89. package/dist/providers/wallet_daemon/webrtc.d.ts +20 -0
  90. package/dist/providers/wallet_daemon/webrtc.js +201 -0
  91. package/dist/providers/wallet_daemon/webrtc_transport.d.ts +10 -0
  92. package/dist/providers/wallet_daemon/webrtc_transport.js +18 -0
  93. package/dist/providers/walletconnect/index.d.ts +23 -0
  94. package/dist/providers/walletconnect/index.js +217 -0
  95. package/dist/templates/Account.d.ts +65 -0
  96. package/dist/templates/Account.js +31 -0
  97. package/dist/templates/Pool.d.ts +30 -0
  98. package/dist/templates/Pool.js +20 -0
  99. package/dist/templates/Tariswap.d.ts +65 -0
  100. package/dist/templates/Tariswap.js +36 -0
  101. package/dist/templates/TemplateFactory.d.ts +9 -0
  102. package/dist/templates/TemplateFactory.js +18 -0
  103. package/dist/templates/TestFaucet.d.ts +49 -0
  104. package/dist/templates/TestFaucet.js +31 -0
  105. package/dist/templates/index.d.ts +4 -0
  106. package/dist/templates/index.js +4 -0
  107. package/dist/utils.d.ts +2 -0
  108. package/dist/utils.js +22 -0
  109. package/package.json +8 -4
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Get the installed snaps in MetaMask.
3
+ *
4
+ * @param provider - The MetaMask inpage provider.
5
+ * @returns The snaps installed in MetaMask.
6
+ */
7
+ export const getSnaps = async (provider) => (await provider.request({
8
+ method: 'wallet_getSnaps',
9
+ }));
10
+ /**
11
+ * Connect a snap to MetaMask.
12
+ *
13
+ * @param snapId - The ID of the snap.
14
+ * @param params - The params to pass with the snap to connect.
15
+ */
16
+ export const connectSnap = async (provider, snaps) => {
17
+ await provider.request({
18
+ method: 'wallet_requestSnaps',
19
+ params: snaps,
20
+ });
21
+ };
22
+ /**
23
+ * Get the snap from MetaMask.
24
+ *
25
+ * @param version - The version of the snap to install (optional).
26
+ * @returns The snap object returned by the extension.
27
+ */
28
+ export const getSnap = async (provider, snapId, version) => {
29
+ try {
30
+ const snaps = await getSnaps(provider);
31
+ return Object.values(snaps).find((snap) => snap.id === snapId && (!version || snap.version === version));
32
+ }
33
+ catch (e) {
34
+ console.log('Failed to obtain installed snap', e);
35
+ return undefined;
36
+ }
37
+ };
38
+ export const isLocalSnap = (snapId) => snapId.startsWith('local:');
39
+ /**
40
+ * Detect if the wallet injecting the ethereum object is MetaMask Flask.
41
+ *
42
+ * @returns True if the MetaMask version is Flask, false otherwise.
43
+ */
44
+ export const isFlask = async (provider) => {
45
+ try {
46
+ const clientVersion = await provider.request({
47
+ method: 'web3_clientVersion',
48
+ });
49
+ const isFlaskDetected = clientVersion?.includes('flask');
50
+ return Boolean(provider && isFlaskDetected);
51
+ }
52
+ catch {
53
+ return false;
54
+ }
55
+ };
@@ -0,0 +1,3 @@
1
+ export * from "../wallet_daemon/tari_permissions";
2
+ export * from "./provider";
3
+ export * from "./types";
@@ -0,0 +1,3 @@
1
+ export * from "../wallet_daemon/tari_permissions";
2
+ export * from "./provider";
3
+ export * from "./types";
@@ -0,0 +1,23 @@
1
+ import { SubmitTransactionRequest, TransactionResult, SubmitTransactionResponse, Account, Substate, TemplateDefinition, VaultBalances, ListSubstatesResponse } from "../types";
2
+ import { TariUniverseProviderParameters, WindowSize } from "./types";
3
+ import { TariProvider } from "../index";
4
+ import { AccountsGetBalancesResponse, SubstateType } from "@tari-project/wallet_jrpc_client";
5
+ export declare class TariUniverseProvider implements TariProvider {
6
+ params: TariUniverseProviderParameters;
7
+ providerName: string;
8
+ private __id;
9
+ constructor(params: TariUniverseProviderParameters);
10
+ private sendRequest;
11
+ isConnected(): boolean;
12
+ getPublicKey(): Promise<string>;
13
+ listSubstates(filter_by_template: string | null, filter_by_type: SubstateType | null, limit: number | null, offset: number | null): Promise<ListSubstatesResponse>;
14
+ getConfidentialVaultBalances(viewKeyId: number, vaultId: string, min: number | null, max: number | null): Promise<VaultBalances>;
15
+ createFreeTestCoins(): Promise<void>;
16
+ requestParentSize(): Promise<WindowSize>;
17
+ getAccount(): Promise<Account>;
18
+ getAccountBalances(componentAddress: string): Promise<AccountsGetBalancesResponse>;
19
+ getSubstate(substate_id: string): Promise<Substate>;
20
+ submitTransaction(req: SubmitTransactionRequest): Promise<SubmitTransactionResponse>;
21
+ getTransactionResult(transactionId: string): Promise<TransactionResult>;
22
+ getTemplateDefinition(template_address: string): Promise<TemplateDefinition>;
23
+ }
@@ -0,0 +1,88 @@
1
+ export class TariUniverseProvider {
2
+ params;
3
+ providerName = "TariUniverse";
4
+ __id = 0;
5
+ constructor(params) {
6
+ this.params = params;
7
+ const filterResizeEvent = function (event) {
8
+ if (event.data && event.data.type === "resize") {
9
+ const resizeEvent = new CustomEvent("resize", {
10
+ detail: { width: event.data.width, height: event.data.height },
11
+ });
12
+ window.dispatchEvent(resizeEvent);
13
+ }
14
+ };
15
+ window.addEventListener("message", (event) => filterResizeEvent(event), false);
16
+ }
17
+ async sendRequest(req) {
18
+ const id = ++this.__id;
19
+ return new Promise(function (resolve, reject) {
20
+ const event_ref = function (resp) {
21
+ if (resp.data.resultError) {
22
+ window.removeEventListener("message", event_ref);
23
+ reject(resp.data.resultError);
24
+ }
25
+ if (resp && resp.data && resp.data.id && resp.data.id == id && resp.data.type === "provider-call") {
26
+ window.removeEventListener("message", event_ref);
27
+ resolve(resp.data.result);
28
+ }
29
+ };
30
+ window.addEventListener("message", event_ref, false);
31
+ window.parent.postMessage({ ...req, id, type: "provider-call" }, "*");
32
+ });
33
+ }
34
+ isConnected() {
35
+ return true;
36
+ }
37
+ getPublicKey() {
38
+ return this.sendRequest({ methodName: "getPublicKey", args: [] });
39
+ }
40
+ async listSubstates(filter_by_template, filter_by_type, limit, offset) {
41
+ return this.sendRequest({
42
+ methodName: "listSubstates",
43
+ args: [filter_by_template, filter_by_type, limit, offset],
44
+ });
45
+ }
46
+ getConfidentialVaultBalances(viewKeyId, vaultId, min, max) {
47
+ return this.sendRequest({
48
+ methodName: "getConfidentialVaultBalances",
49
+ args: [viewKeyId, vaultId, min, max],
50
+ });
51
+ }
52
+ async createFreeTestCoins() {
53
+ return this.sendRequest({ methodName: "createFreeTestCoins", args: [] });
54
+ }
55
+ requestParentSize() {
56
+ return this.sendRequest({ methodName: "requestParentSize", args: [] });
57
+ }
58
+ async getAccount() {
59
+ return this.sendRequest({ methodName: "getAccount", args: [] });
60
+ }
61
+ async getAccountBalances(componentAddress) {
62
+ return this.sendRequest({
63
+ methodName: "getAccountBalances",
64
+ args: [componentAddress],
65
+ });
66
+ }
67
+ async getSubstate(substate_id) {
68
+ return this.sendRequest({
69
+ methodName: "getSubstate",
70
+ args: [substate_id],
71
+ });
72
+ }
73
+ async submitTransaction(req) {
74
+ return this.sendRequest({
75
+ methodName: "submitTransaction",
76
+ args: [req],
77
+ });
78
+ }
79
+ async getTransactionResult(transactionId) {
80
+ return this.sendRequest({
81
+ methodName: "getTransactionResult",
82
+ args: [transactionId],
83
+ });
84
+ }
85
+ async getTemplateDefinition(template_address) {
86
+ return this.sendRequest({ methodName: "getTemplateDefinition", args: [template_address] });
87
+ }
88
+ }
@@ -0,0 +1,30 @@
1
+ import { TariPermissions } from "../wallet_daemon";
2
+ import { TariUniverseProvider } from "./provider";
3
+ export type TariUniverseProviderParameters = {
4
+ permissions: TariPermissions;
5
+ optionalPermissions: TariPermissions;
6
+ name?: string;
7
+ onConnection?: () => void;
8
+ };
9
+ export type WindowSize = {
10
+ width: number;
11
+ height: number;
12
+ };
13
+ export type PickMatching<T, V> = {
14
+ [K in keyof T as T[K] extends V ? K : never]: T[K];
15
+ };
16
+ export type ExtractMethods<T> = PickMatching<T, Function>;
17
+ export type ProviderMethods = ExtractMethods<TariUniverseProvider>;
18
+ export type ProviderMethodNames = keyof ProviderMethods;
19
+ export type ProviderReturnType<T extends ProviderMethodNames> = Awaited<ReturnType<ProviderMethods[T]>>;
20
+ export type ProviderRequest<T extends ProviderMethodNames> = {
21
+ id: number;
22
+ methodName: T;
23
+ args: Parameters<ProviderMethods[T]>;
24
+ };
25
+ export type ProviderResponse<T extends ProviderMethodNames> = {
26
+ id: number;
27
+ type: "provider-call";
28
+ result: ProviderReturnType<T>;
29
+ resultError?: string;
30
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,66 @@
1
+ import { FinalizeResult } from "@tari-project/typescript-bindings";
2
+ export type SubstateMetadata = {
3
+ substate_id: string;
4
+ module_name: string | null;
5
+ version: number;
6
+ template_address: string | null;
7
+ };
8
+ export type SubstateRequirement = {
9
+ substate_id: string;
10
+ version?: number | null;
11
+ };
12
+ export type SubmitTransactionRequest = {
13
+ account_id: number;
14
+ instructions: object[];
15
+ fee_instructions: object[];
16
+ inputs: object[];
17
+ input_refs: object[];
18
+ required_substates: SubstateRequirement[];
19
+ is_dry_run: boolean;
20
+ min_epoch: number | null;
21
+ max_epoch: number | null;
22
+ };
23
+ export type SubmitTransactionResponse = {
24
+ transaction_id: string;
25
+ };
26
+ export type TransactionResult = {
27
+ transaction_id: string;
28
+ status: TransactionStatus;
29
+ result: FinalizeResult | null;
30
+ };
31
+ export declare enum TransactionStatus {
32
+ New = 0,
33
+ DryRun = 1,
34
+ Pending = 2,
35
+ Accepted = 3,
36
+ Rejected = 4,
37
+ InvalidTransaction = 5,
38
+ OnlyFeeAccepted = 6
39
+ }
40
+ export interface Account {
41
+ account_id: number;
42
+ address: string;
43
+ public_key: string;
44
+ resources: VaultData[];
45
+ }
46
+ export interface VaultData {
47
+ type: string;
48
+ balance: number;
49
+ resource_address: string;
50
+ }
51
+ export interface VaultBalances {
52
+ balances: Map<string, number | null>;
53
+ }
54
+ export interface TemplateDefinition {
55
+ [key: string]: any;
56
+ }
57
+ export interface Substate {
58
+ value: any;
59
+ address: {
60
+ substate_id: string;
61
+ version: number;
62
+ };
63
+ }
64
+ export type ListSubstatesResponse = {
65
+ substates: Array<SubstateMetadata>;
66
+ };
@@ -0,0 +1,10 @@
1
+ export var TransactionStatus;
2
+ (function (TransactionStatus) {
3
+ TransactionStatus[TransactionStatus["New"] = 0] = "New";
4
+ TransactionStatus[TransactionStatus["DryRun"] = 1] = "DryRun";
5
+ TransactionStatus[TransactionStatus["Pending"] = 2] = "Pending";
6
+ TransactionStatus[TransactionStatus["Accepted"] = 3] = "Accepted";
7
+ TransactionStatus[TransactionStatus["Rejected"] = 4] = "Rejected";
8
+ TransactionStatus[TransactionStatus["InvalidTransaction"] = 5] = "InvalidTransaction";
9
+ TransactionStatus[TransactionStatus["OnlyFeeAccepted"] = 6] = "OnlyFeeAccepted";
10
+ })(TransactionStatus || (TransactionStatus = {}));
@@ -0,0 +1,3 @@
1
+ export { TariConnection } from "./webrtc";
2
+ export * from "./tari_permissions";
3
+ export * from "./provider";
@@ -0,0 +1,3 @@
1
+ export { TariConnection } from "./webrtc";
2
+ export * from "./tari_permissions";
3
+ export * from "./provider";
@@ -0,0 +1,35 @@
1
+ import { TariPermissions } from "./tari_permissions";
2
+ import { TariProvider } from '../index';
3
+ import { SubmitTransactionRequest, TransactionResult, SubmitTransactionResponse, VaultBalances, TemplateDefinition, Substate, ListSubstatesResponse } from "../types";
4
+ import { Account } from "../types";
5
+ import { WalletDaemonClient, SubstateType } from "@tari-project/wallet_jrpc_client";
6
+ export declare const WalletDaemonNotConnected = "WALLET_DAEMON_NOT_CONNECTED";
7
+ export declare const Unsupported = "UNSUPPORTED";
8
+ export type WalletDaemonParameters = {
9
+ signalingServerUrl?: string;
10
+ permissions: TariPermissions;
11
+ optionalPermissions: TariPermissions;
12
+ webRtcConfig?: RTCConfiguration;
13
+ name?: string;
14
+ onConnection?: () => void;
15
+ };
16
+ export declare class WalletDaemonTariProvider implements TariProvider {
17
+ providerName: string;
18
+ params: WalletDaemonParameters;
19
+ client: WalletDaemonClient;
20
+ private constructor();
21
+ static build(params: WalletDaemonParameters): Promise<WalletDaemonTariProvider>;
22
+ get token(): string | undefined;
23
+ get tokenUrl(): string | undefined;
24
+ isConnected(): boolean;
25
+ createFreeTestCoins(): Promise<Account>;
26
+ getAccount(): Promise<Account>;
27
+ getAccountBalances(componentAddress: string): Promise<unknown>;
28
+ getSubstate(substate_id: string): Promise<Substate>;
29
+ submitTransaction(req: SubmitTransactionRequest): Promise<SubmitTransactionResponse>;
30
+ getTransactionResult(transactionId: string): Promise<TransactionResult>;
31
+ getPublicKey(branch: string, index: number): Promise<string>;
32
+ getTemplateDefinition(template_address: string): Promise<TemplateDefinition>;
33
+ getConfidentialVaultBalances(viewKeyId: number, vaultId: string, min?: number | null, max?: number | null): Promise<VaultBalances>;
34
+ listSubstates(filter_by_template: string | null, filter_by_type: SubstateType | null, limit: number | null, offset: number | null): Promise<ListSubstatesResponse>;
35
+ }
@@ -0,0 +1,173 @@
1
+ import { TariPermissions, } from "./tari_permissions";
2
+ import { TariConnection } from "./webrtc";
3
+ import { TransactionStatus, } from "../types";
4
+ import { WalletDaemonClient, stringToSubstateId, substateIdToString, } from "@tari-project/wallet_jrpc_client";
5
+ import { WebRtcRpcTransport } from "./webrtc_transport";
6
+ export const WalletDaemonNotConnected = 'WALLET_DAEMON_NOT_CONNECTED';
7
+ export const Unsupported = 'UNSUPPORTED';
8
+ export class WalletDaemonTariProvider {
9
+ providerName = "WalletDaemon";
10
+ params;
11
+ client;
12
+ constructor(params, connection) {
13
+ this.params = params;
14
+ this.client = connection;
15
+ }
16
+ static async build(params) {
17
+ const allPermissions = new TariPermissions();
18
+ allPermissions.addPermissions(params.permissions);
19
+ allPermissions.addPermissions(params.optionalPermissions);
20
+ console.log({ allPermissions });
21
+ let connection = new TariConnection(params.signalingServerUrl, params.webRtcConfig);
22
+ const client = WalletDaemonClient.new(WebRtcRpcTransport.new(connection));
23
+ await connection.init(allPermissions, (conn) => {
24
+ params.onConnection?.();
25
+ if (conn.token) {
26
+ client.setToken(conn.token);
27
+ }
28
+ });
29
+ return new WalletDaemonTariProvider(params, client);
30
+ }
31
+ get token() {
32
+ return this.client.getTransport().token();
33
+ }
34
+ get tokenUrl() {
35
+ if (!this.token) {
36
+ return undefined;
37
+ }
38
+ const name = this.params.name && encodeURIComponent(this.params.name) || '';
39
+ const token = this.token;
40
+ const permissions = JSON.stringify(this.params.permissions);
41
+ const optionalPermissions = JSON.stringify(this.params.optionalPermissions);
42
+ return `tari://${name}/${token}/${permissions}/${optionalPermissions}`;
43
+ }
44
+ isConnected() {
45
+ return this.client.getTransport().isConnected();
46
+ }
47
+ async createFreeTestCoins() {
48
+ const res = await this.client.createFreeTestCoins({
49
+ account: { Name: "template_web" },
50
+ amount: 1000000,
51
+ max_fee: null,
52
+ key_id: 0
53
+ });
54
+ return {
55
+ account_id: res.account.key_index,
56
+ address: res.account.address.Component,
57
+ public_key: res.public_key,
58
+ resources: []
59
+ };
60
+ }
61
+ async getAccount() {
62
+ const { account, public_key } = await this.client.accountsGetDefault({});
63
+ const { balances } = await this.client.accountsGetBalances({ account: { ComponentAddress: account.address.Component }, refresh: false });
64
+ return {
65
+ account_id: account.key_index,
66
+ address: account.address.Component,
67
+ public_key,
68
+ // TODO: should be vaults not resources
69
+ resources: balances.map((b) => ({
70
+ type: b.resource_type,
71
+ resource_address: b.resource_address,
72
+ balance: b.balance + b.confidential_balance,
73
+ vault_id: ('Vault' in b.vault_address) ? b.vault_address.Vault : b.vault_address,
74
+ token_symbol: b.token_symbol,
75
+ }))
76
+ };
77
+ }
78
+ async getAccountBalances(componentAddress) {
79
+ return await this.client.accountsGetBalances({ account: { ComponentAddress: componentAddress }, refresh: true });
80
+ }
81
+ async getSubstate(substate_id) {
82
+ const substateId = stringToSubstateId(substate_id);
83
+ const { value, record } = await this.client.substatesGet({ substate_id: substateId });
84
+ return {
85
+ value,
86
+ address: {
87
+ substate_id: substateIdToString(record.substate_id),
88
+ version: record.version
89
+ }
90
+ };
91
+ }
92
+ async submitTransaction(req) {
93
+ const params = {
94
+ transaction: null,
95
+ signing_key_index: req.account_id,
96
+ fee_instructions: req.fee_instructions,
97
+ instructions: req.instructions,
98
+ inputs: req.required_substates.map((s) => ({
99
+ // TODO: Hmm The bindings want a SubstateId object, but the wallet only wants a string. Any is used to skip type checking here
100
+ substate_id: s.substate_id,
101
+ version: s.version
102
+ })),
103
+ input_refs: [],
104
+ override_inputs: false,
105
+ is_dry_run: req.is_dry_run,
106
+ proof_ids: [],
107
+ min_epoch: null,
108
+ max_epoch: null,
109
+ };
110
+ const res = await this.client.submitTransaction(params);
111
+ return { transaction_id: res.transaction_id };
112
+ }
113
+ async getTransactionResult(transactionId) {
114
+ const res = await this.client.getTransactionResult({ transaction_id: transactionId });
115
+ return {
116
+ transaction_id: transactionId,
117
+ status: convertStringToTransactionStatus(res.status),
118
+ result: res.result,
119
+ };
120
+ }
121
+ async getPublicKey(branch, index) {
122
+ const res = await this.client.createKey({ branch: branch, specific_index: index });
123
+ return res.public_key;
124
+ }
125
+ async getTemplateDefinition(template_address) {
126
+ let resp = await this.client.templatesGet({ template_address });
127
+ return resp.template_definition;
128
+ }
129
+ async getConfidentialVaultBalances(viewKeyId, vaultId, min = null, max = null) {
130
+ const res = await this.client.viewVaultBalance({
131
+ view_key_id: viewKeyId,
132
+ vault_id: vaultId,
133
+ minimum_expected_value: min,
134
+ maximum_expected_value: max,
135
+ });
136
+ return { balances: res.balances };
137
+ }
138
+ async listSubstates(filter_by_template, filter_by_type, limit, offset) {
139
+ const resp = await this.client.substatesList({
140
+ filter_by_template,
141
+ filter_by_type,
142
+ limit,
143
+ offset
144
+ });
145
+ const substates = resp.substates.map((s) => ({
146
+ substate_id: substateIdToString(s.substate_id),
147
+ module_name: s.module_name,
148
+ version: s.version,
149
+ template_address: s.template_address
150
+ }));
151
+ return { substates };
152
+ }
153
+ }
154
+ function convertStringToTransactionStatus(status) {
155
+ switch (status) {
156
+ case "New":
157
+ return TransactionStatus.New;
158
+ case "DryRun":
159
+ return TransactionStatus.DryRun;
160
+ case "Pending":
161
+ return TransactionStatus.Pending;
162
+ case "Accepted":
163
+ return TransactionStatus.Accepted;
164
+ case "Rejected":
165
+ return TransactionStatus.Rejected;
166
+ case "InvalidTransaction":
167
+ return TransactionStatus.InvalidTransaction;
168
+ case "OnlyFeeAccepted":
169
+ return TransactionStatus.OnlyFeeAccepted;
170
+ default:
171
+ throw new Error(`Unknown status: ${status}`);
172
+ }
173
+ }