@tari-project/tarijs 0.3.1 → 0.4.1
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/ISSUE_TEMPLATE/bug_report.md +36 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +27 -0
- package/.github/dependabot.yml +8 -0
- package/.github/workflows/ci.yml +25 -0
- package/.github/workflows/npm_publish.yml +26 -0
- package/.github/workflows/pr_signed_commits_check.yml +19 -0
- package/.github/workflows/pr_title.yml +30 -0
- package/.moon/toolchain.yml +6 -0
- package/.moon/workspace.yml +32 -0
- package/.prettierrc +12 -0
- package/.prototools +9 -0
- package/CODEOWNERS +3 -0
- package/README.md +9 -8
- package/TODO.md +12 -0
- package/package.json +6 -24
- package/packages/builders/moon.yml +55 -0
- package/packages/builders/package.json +30 -0
- package/packages/builders/src/helpers/submitTransaction.ts +97 -0
- package/{dist/builders/helpers/workspace.js → packages/builders/src/helpers/workspace.ts} +10 -7
- package/packages/builders/src/index.ts +9 -0
- package/packages/builders/src/transaction/TransactionBuilder.ts +276 -0
- package/packages/builders/src/transaction/TransactionRequest.ts +93 -0
- package/packages/builders/src/transaction/index.ts +2 -0
- package/packages/builders/tsconfig.json +24 -0
- package/packages/metamask_provider/moon.yml +55 -0
- package/packages/metamask_provider/package.json +30 -0
- package/packages/metamask_provider/src/index.ts +232 -0
- package/packages/metamask_provider/src/utils.ts +86 -0
- package/packages/metamask_provider/tsconfig.json +21 -0
- package/packages/tari_permissions/moon.yml +55 -0
- package/packages/tari_permissions/package.json +26 -0
- package/packages/tari_permissions/src/index.ts +1 -0
- package/packages/tari_permissions/src/tari_permissions.ts +312 -0
- package/packages/tari_permissions/tsconfig.json +15 -0
- package/packages/tari_provider/moon.yml +55 -0
- package/packages/tari_provider/package.json +27 -0
- package/packages/tari_provider/src/TariProvider.ts +35 -0
- package/packages/tari_provider/src/index.ts +3 -0
- package/packages/tari_provider/src/types.ts +82 -0
- package/packages/tari_provider/tsconfig.json +11 -0
- package/packages/tari_universe/moon.yml +55 -0
- package/packages/tari_universe/package.json +31 -0
- package/{dist/providers/tari_universe/index.d.ts → packages/tari_universe/src/index.ts} +1 -1
- package/packages/tari_universe/src/provider.ts +135 -0
- package/{dist/providers/tari_universe/types.d.ts → packages/tari_universe/src/types.ts} +20 -17
- package/packages/tari_universe/src/utils.ts +23 -0
- package/packages/tari_universe/tsconfig.json +24 -0
- package/packages/tarijs/integration-tests/.env +1 -0
- package/packages/tarijs/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +191 -0
- package/packages/tarijs/moon.yml +63 -0
- package/packages/tarijs/package.json +39 -0
- package/packages/tarijs/src/index.ts +69 -0
- package/packages/tarijs/src/network.ts +8 -0
- package/packages/tarijs/src/templates/Account.ts +98 -0
- package/packages/tarijs/src/templates/Pool.ts +42 -0
- package/packages/tarijs/src/templates/Tariswap.ts +101 -0
- package/packages/tarijs/src/templates/TemplateFactory.ts +22 -0
- package/packages/tarijs/src/templates/TestFaucet.ts +72 -0
- package/{dist/utils.js → packages/tarijs/src/utils.ts} +4 -3
- package/packages/tarijs/tsconfig.json +39 -0
- package/packages/tarijs/vitest.config.ts +9 -0
- package/packages/tarijs_types/moon.yml +55 -0
- package/packages/tarijs_types/package.json +27 -0
- package/packages/tarijs_types/src/Amount.ts +113 -0
- package/packages/tarijs_types/src/Arg.ts +3 -0
- package/packages/tarijs_types/src/ComponentAddress.ts +3 -0
- package/packages/tarijs_types/src/ConfidentialClaim.ts +9 -0
- package/packages/tarijs_types/src/ConfidentialOutput.ts +9 -0
- package/packages/tarijs_types/src/ConfidentialOutputStatement.ts +10 -0
- package/packages/tarijs_types/src/ConfidentialStatement.ts +9 -0
- package/packages/tarijs_types/src/ConfidentialWithdrawProof.ts +8 -0
- package/packages/tarijs_types/src/ElgamalVerifiableBalance.ts +4 -0
- package/packages/tarijs_types/src/Epoch.ts +3 -0
- package/packages/tarijs_types/src/FinalizeResult.ts +17 -0
- package/packages/tarijs_types/src/Instruction.ts +29 -0
- package/{dist/builders/types/ResourceAddress.js → packages/tarijs_types/src/ResourceAddress.ts} +2 -1
- package/{dist/builders/types/SubstateDiff.d.ts → packages/tarijs_types/src/SubstateDiff.ts} +4 -2
- package/{dist/builders/types/SubstateRequirement.d.ts → packages/tarijs_types/src/SubstateRequirement.ts} +3 -2
- package/{dist/builders/types/TemplateAddress.js → packages/tarijs_types/src/TemplateAddress.ts} +2 -1
- package/{dist/builders/types/Transaction.d.ts → packages/tarijs_types/src/Transaction.ts} +9 -8
- package/packages/tarijs_types/src/TransactionId.ts +4 -0
- package/packages/tarijs_types/src/TransactionResult.ts +26 -0
- package/packages/tarijs_types/src/TransactionSignature.ts +4 -0
- package/packages/tarijs_types/src/UnsignedTransaction.ts +15 -0
- package/{dist/builders/types/VersionedSubstateId.d.ts → packages/tarijs_types/src/VersionedSubstateId.ts} +3 -2
- package/packages/tarijs_types/src/ViewableBalanceProof.ts +12 -0
- package/{dist/builders/types/Workspace.d.ts → packages/tarijs_types/src/Workspace.ts} +1 -1
- package/{dist/builders/types/index.d.ts → packages/tarijs_types/src/index.ts} +4 -3
- package/packages/tarijs_types/tsconfig.json +15 -0
- package/packages/wallet_daemon/moon.yml +55 -0
- package/packages/wallet_daemon/package.json +29 -0
- package/{dist/providers/wallet_daemon/index.d.ts → packages/wallet_daemon/src/index.ts} +3 -1
- package/packages/wallet_daemon/src/provider.ts +263 -0
- package/packages/wallet_daemon/src/webrtc.ts +229 -0
- package/packages/wallet_daemon/src/webrtc_transport.ts +27 -0
- package/packages/wallet_daemon/tsconfig.json +21 -0
- package/packages/walletconnect/moon.yml +55 -0
- package/packages/walletconnect/package.json +32 -0
- package/packages/walletconnect/src/index.ts +274 -0
- package/packages/walletconnect/tsconfig.json +21 -0
- package/pnpm-workspace.yaml +14 -0
- package/tsconfig.json +42 -0
- package/dist/builders/helpers/index.js +0 -2
- package/dist/builders/helpers/submitTransaction.d.ts +0 -13
- package/dist/builders/helpers/submitTransaction.js +0 -62
- package/dist/builders/helpers/workspace.d.ts +0 -23
- package/dist/builders/index.d.ts +0 -3
- package/dist/builders/index.js +0 -3
- package/dist/builders/transaction/TransactionBuilder.d.ts +0 -44
- package/dist/builders/transaction/TransactionBuilder.js +0 -164
- package/dist/builders/transaction/TransactionRequest.d.ts +0 -27
- package/dist/builders/transaction/TransactionRequest.js +0 -67
- package/dist/builders/transaction/index.d.ts +0 -2
- package/dist/builders/transaction/index.js +0 -2
- package/dist/builders/types/Amount.d.ts +0 -23
- package/dist/builders/types/Amount.js +0 -93
- package/dist/builders/types/Arg.d.ts +0 -1
- package/dist/builders/types/Arg.js +0 -1
- package/dist/builders/types/Builder.d.ts +0 -47
- package/dist/builders/types/Builder.js +0 -1
- package/dist/builders/types/ComponentAddress.d.ts +0 -1
- package/dist/builders/types/ComponentAddress.js +0 -1
- package/dist/builders/types/ConfidentialClaim.d.ts +0 -8
- package/dist/builders/types/ConfidentialClaim.js +0 -1
- package/dist/builders/types/ConfidentialOutput.d.ts +0 -8
- package/dist/builders/types/ConfidentialOutput.js +0 -1
- package/dist/builders/types/ConfidentialOutputStatement.d.ts +0 -9
- package/dist/builders/types/ConfidentialOutputStatement.js +0 -1
- package/dist/builders/types/ConfidentialStatement.d.ts +0 -8
- package/dist/builders/types/ConfidentialStatement.js +0 -1
- package/dist/builders/types/ConfidentialWithdrawProof.d.ts +0 -7
- package/dist/builders/types/ConfidentialWithdrawProof.js +0 -1
- package/dist/builders/types/ElgamalVerifiableBalance.d.ts +0 -4
- package/dist/builders/types/ElgamalVerifiableBalance.js +0 -1
- package/dist/builders/types/Epoch.d.ts +0 -1
- package/dist/builders/types/Epoch.js +0 -1
- package/dist/builders/types/FinalizeResult.d.ts +0 -20
- package/dist/builders/types/FinalizeResult.js +0 -1
- package/dist/builders/types/Instruction.d.ts +0 -56
- package/dist/builders/types/Instruction.js +0 -1
- package/dist/builders/types/ResourceAddress.d.ts +0 -1
- package/dist/builders/types/SubstateDiff.js +0 -1
- package/dist/builders/types/SubstateRequirement.js +0 -1
- package/dist/builders/types/TemplateAddress.d.ts +0 -1
- package/dist/builders/types/Transaction.js +0 -1
- package/dist/builders/types/TransactionId.d.ts +0 -1
- package/dist/builders/types/TransactionId.js +0 -1
- package/dist/builders/types/TransactionResult.d.ts +0 -22
- package/dist/builders/types/TransactionResult.js +0 -10
- package/dist/builders/types/TransactionSignature.d.ts +0 -4
- package/dist/builders/types/TransactionSignature.js +0 -1
- package/dist/builders/types/UnsignedTransaction.d.ts +0 -12
- package/dist/builders/types/UnsignedTransaction.js +0 -1
- package/dist/builders/types/VersionedSubstateId.js +0 -1
- package/dist/builders/types/ViewableBalanceProof.d.ts +0 -10
- package/dist/builders/types/ViewableBalanceProof.js +0 -2
- package/dist/builders/types/Workspace.js +0 -1
- package/dist/builders/types/index.js +0 -2
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -12
- package/dist/providers/index.d.ts +0 -16
- package/dist/providers/index.js +0 -1
- package/dist/providers/metamask/index.d.ts +0 -30
- package/dist/providers/metamask/index.js +0 -168
- package/dist/providers/metamask/utils.d.ts +0 -38
- package/dist/providers/metamask/utils.js +0 -55
- package/dist/providers/tari_universe/index.js +0 -3
- package/dist/providers/tari_universe/provider.d.ts +0 -23
- package/dist/providers/tari_universe/provider.js +0 -89
- package/dist/providers/tari_universe/types.js +0 -1
- package/dist/providers/tari_universe/utils.d.ts +0 -2
- package/dist/providers/tari_universe/utils.js +0 -16
- package/dist/providers/types.d.ts +0 -69
- package/dist/providers/types.js +0 -10
- package/dist/providers/wallet_daemon/index.js +0 -3
- package/dist/providers/wallet_daemon/provider.d.ts +0 -43
- package/dist/providers/wallet_daemon/provider.js +0 -198
- package/dist/providers/wallet_daemon/tari_permissions.d.ts +0 -216
- package/dist/providers/wallet_daemon/tari_permissions.js +0 -282
- package/dist/providers/wallet_daemon/webrtc.d.ts +0 -20
- package/dist/providers/wallet_daemon/webrtc.js +0 -201
- package/dist/providers/wallet_daemon/webrtc_transport.d.ts +0 -10
- package/dist/providers/wallet_daemon/webrtc_transport.js +0 -18
- package/dist/providers/walletconnect/index.d.ts +0 -23
- package/dist/providers/walletconnect/index.js +0 -221
- package/dist/templates/Account.d.ts +0 -65
- package/dist/templates/Account.js +0 -31
- package/dist/templates/Pool.d.ts +0 -30
- package/dist/templates/Pool.js +0 -20
- package/dist/templates/Tariswap.d.ts +0 -65
- package/dist/templates/Tariswap.js +0 -36
- package/dist/templates/TemplateFactory.d.ts +0 -9
- package/dist/templates/TemplateFactory.js +0 -18
- package/dist/templates/TestFaucet.d.ts +0 -49
- package/dist/templates/TestFaucet.js +0 -31
- package/dist/templates/index.js +0 -5
- package/dist/utils.d.ts +0 -2
- /package/{dist/builders/helpers/index.d.ts → packages/builders/src/helpers/index.ts} +0 -0
- /package/{dist/templates/index.d.ts → packages/tarijs/src/templates/index.ts} +0 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SubmitTransactionResponse,
|
|
3
|
+
Account,
|
|
4
|
+
Substate,
|
|
5
|
+
TemplateDefinition,
|
|
6
|
+
VaultBalances,
|
|
7
|
+
ListSubstatesResponse,
|
|
8
|
+
SubmitTransactionRequest,
|
|
9
|
+
TariProvider,
|
|
10
|
+
TransactionResult
|
|
11
|
+
} from "@tari-project/tari-provider";
|
|
12
|
+
import {
|
|
13
|
+
ProviderRequest,
|
|
14
|
+
ProviderMethodNames,
|
|
15
|
+
ProviderReturnType,
|
|
16
|
+
TariUniverseProviderParameters,
|
|
17
|
+
WindowSize,
|
|
18
|
+
} from "./types";
|
|
19
|
+
import { } from "@tari-project/tari-provider";
|
|
20
|
+
import { AccountsGetBalancesResponse, SubstateType } from "@tari-project/wallet_jrpc_client";
|
|
21
|
+
import { sendProviderCall } from "./utils";
|
|
22
|
+
|
|
23
|
+
export class TariUniverseProvider implements TariProvider {
|
|
24
|
+
public providerName = "TariUniverse";
|
|
25
|
+
private __id = 0;
|
|
26
|
+
|
|
27
|
+
public constructor(public params: TariUniverseProviderParameters) {
|
|
28
|
+
const filterResizeEvent = function (event: MessageEvent) {
|
|
29
|
+
if (event.data && event.data.type === "resize") {
|
|
30
|
+
const resizeEvent = new CustomEvent("resize", {
|
|
31
|
+
detail: { width: event.data.width, height: event.data.height },
|
|
32
|
+
});
|
|
33
|
+
window.dispatchEvent(resizeEvent);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
window.addEventListener("message", (event) => filterResizeEvent(event), false);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private async sendRequest<MethodName extends ProviderMethodNames>(
|
|
40
|
+
req: Omit<ProviderRequest<MethodName>, "id">,
|
|
41
|
+
): Promise<ProviderReturnType<MethodName>> {
|
|
42
|
+
const id = ++this.__id;
|
|
43
|
+
return sendProviderCall(req, id);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public isConnected(): boolean {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public getPublicKey(): Promise<string> {
|
|
51
|
+
return this.sendRequest<"getPublicKey">({ methodName: "getPublicKey", args: [] });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public async listSubstates(
|
|
55
|
+
filter_by_template: string | null,
|
|
56
|
+
filter_by_type: SubstateType | null,
|
|
57
|
+
limit: number | null,
|
|
58
|
+
offset: number | null,
|
|
59
|
+
): Promise<ListSubstatesResponse> {
|
|
60
|
+
return this.sendRequest<"listSubstates">({
|
|
61
|
+
methodName: "listSubstates",
|
|
62
|
+
args: [filter_by_template, filter_by_type, limit, offset],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public getConfidentialVaultBalances(
|
|
67
|
+
viewKeyId: number,
|
|
68
|
+
vaultId: string,
|
|
69
|
+
min: number | null,
|
|
70
|
+
max: number | null,
|
|
71
|
+
): Promise<VaultBalances> {
|
|
72
|
+
return this.sendRequest({
|
|
73
|
+
methodName: "getConfidentialVaultBalances",
|
|
74
|
+
args: [viewKeyId, vaultId, min, max],
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public async createFreeTestCoins(): Promise<void> {
|
|
79
|
+
return this.sendRequest({ methodName: "createFreeTestCoins", args: [] });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public requestParentSize(): Promise<WindowSize> {
|
|
83
|
+
return this.sendRequest({ methodName: "requestParentSize", args: [] });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public async getAccount(): Promise<Account> {
|
|
87
|
+
const { account_id, address, public_key } = await this.sendRequest({ methodName: "getAccount", args: [] });
|
|
88
|
+
const { balances } = await this.getAccountBalances(address);
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
account_id,
|
|
92
|
+
address,
|
|
93
|
+
public_key,
|
|
94
|
+
resources: balances.map((b: any) => ({
|
|
95
|
+
type: b.resource_type,
|
|
96
|
+
resource_address: b.resource_address,
|
|
97
|
+
balance: b.balance + b.confidential_balance,
|
|
98
|
+
vault_id: "Vault" in b.vault_address ? b.vault_address.Vault : b.vault_address,
|
|
99
|
+
token_symbol: b.token_symbol,
|
|
100
|
+
})),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public async getAccountBalances(componentAddress: string): Promise<AccountsGetBalancesResponse> {
|
|
105
|
+
return this.sendRequest({
|
|
106
|
+
methodName: "getAccountBalances",
|
|
107
|
+
args: [componentAddress],
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public async getSubstate(substate_id: string): Promise<Substate> {
|
|
112
|
+
return this.sendRequest({
|
|
113
|
+
methodName: "getSubstate",
|
|
114
|
+
args: [substate_id],
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public async submitTransaction(req: SubmitTransactionRequest): Promise<SubmitTransactionResponse> {
|
|
119
|
+
return this.sendRequest({
|
|
120
|
+
methodName: "submitTransaction",
|
|
121
|
+
args: [req],
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public async getTransactionResult(transactionId: string): Promise<TransactionResult> {
|
|
126
|
+
return this.sendRequest({
|
|
127
|
+
methodName: "getTransactionResult",
|
|
128
|
+
args: [transactionId],
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public async getTemplateDefinition(template_address: string): Promise<TemplateDefinition> {
|
|
133
|
+
return this.sendRequest({ methodName: "getTemplateDefinition", args: [template_address] });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import { TariPermissions } from "
|
|
1
|
+
import { TariPermissions } from "@tari-project/tari-permissions";
|
|
2
2
|
import { TariUniverseProvider } from "./provider";
|
|
3
|
+
|
|
3
4
|
export type TariUniverseProviderParameters = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
permissions: TariPermissions;
|
|
6
|
+
optionalPermissions: TariPermissions;
|
|
7
|
+
name?: string;
|
|
8
|
+
onConnection?: () => void;
|
|
8
9
|
};
|
|
10
|
+
|
|
9
11
|
export type WindowSize = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
export type PickMatching<T, V> = {
|
|
14
|
-
[K in keyof T as T[K] extends V ? K : never]: T[K];
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
15
14
|
};
|
|
15
|
+
|
|
16
|
+
export type PickMatching<T, V> = { [K in keyof T as T[K] extends V ? K : never]: T[K] };
|
|
16
17
|
export type ExtractMethods<T> = PickMatching<T, Function>;
|
|
17
18
|
export type ProviderMethods = ExtractMethods<TariUniverseProvider>;
|
|
18
19
|
export type ProviderMethodNames = keyof ProviderMethods;
|
|
19
20
|
export type ProviderReturnType<T extends ProviderMethodNames> = Awaited<ReturnType<ProviderMethods[T]>>;
|
|
21
|
+
|
|
20
22
|
export type ProviderRequest<T extends ProviderMethodNames> = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
id: number;
|
|
24
|
+
methodName: T;
|
|
25
|
+
args: Parameters<ProviderMethods[T]>;
|
|
24
26
|
};
|
|
27
|
+
|
|
25
28
|
export type ProviderResponse<T extends ProviderMethodNames> = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
id: number;
|
|
30
|
+
type: "provider-call";
|
|
31
|
+
result: ProviderReturnType<T>;
|
|
32
|
+
resultError?: string;
|
|
30
33
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ProviderMethodNames, ProviderRequest, ProviderResponse, ProviderReturnType } from "./types";
|
|
2
|
+
|
|
3
|
+
export function sendProviderCall<MethodName extends ProviderMethodNames>(
|
|
4
|
+
req: Omit<ProviderRequest<MethodName>, "id">,
|
|
5
|
+
id: number,
|
|
6
|
+
): Promise<ProviderReturnType<MethodName>> {
|
|
7
|
+
return new Promise<ProviderReturnType<MethodName>>((resolve, reject) => {
|
|
8
|
+
const event_ref = (resp: MessageEvent<ProviderResponse<MethodName>>) => {
|
|
9
|
+
if (resp.data.resultError) {
|
|
10
|
+
window.removeEventListener("message", event_ref);
|
|
11
|
+
reject(resp.data.resultError);
|
|
12
|
+
}
|
|
13
|
+
if (resp && resp.data && resp.data.id && resp.data.id === id && resp.data.type === "provider-call") {
|
|
14
|
+
window.removeEventListener("message", event_ref);
|
|
15
|
+
resolve(resp.data.result);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
window.addEventListener("message", event_ref, false);
|
|
20
|
+
|
|
21
|
+
window.parent.postMessage({ ...req, id, type: "provider-call" }, "*");
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "ES2020",
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"moduleResolution": "Bundler",
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./src"
|
|
9
|
+
},
|
|
10
|
+
"include": [
|
|
11
|
+
"src/**/*"
|
|
12
|
+
],
|
|
13
|
+
"references": [
|
|
14
|
+
{
|
|
15
|
+
"path": "../tari_permissions"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "../tari_provider"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"path": "../tarijs_types"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
WALLET_DAEMON_JSON_RPC_URL=http://127.0.0.1:12011/json_rpc
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { assert, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { SubmitTransactionRequest, TariPermissions, WalletDaemonTariProvider } from "../../src";
|
|
4
|
+
|
|
5
|
+
function buildProvider(): Promise<WalletDaemonTariProvider> {
|
|
6
|
+
const permissions = new TariPermissions().addPermission("Admin");
|
|
7
|
+
const serverUrl = process.env.WALLET_DAEMON_JSON_RPC_URL;
|
|
8
|
+
assert(serverUrl, "WALLET_DAEMON_JSON_RPC_URL must be set");
|
|
9
|
+
return WalletDaemonTariProvider.buildFetchProvider({
|
|
10
|
+
permissions,
|
|
11
|
+
serverUrl,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe("WalletDaemonTariProvider", () => {
|
|
16
|
+
describe("providerName", () => {
|
|
17
|
+
it("returns the provider name", async () => {
|
|
18
|
+
const provider = await buildProvider();
|
|
19
|
+
expect(provider.providerName).toBe("WalletDaemon");
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("isConnected", () => {
|
|
24
|
+
it("is always connected", async () => {
|
|
25
|
+
const provider = await buildProvider();
|
|
26
|
+
expect(provider.isConnected()).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("getAccount", () => {
|
|
31
|
+
it("returns account information", async () => {
|
|
32
|
+
const provider = await buildProvider();
|
|
33
|
+
const account = await provider.getAccount();
|
|
34
|
+
|
|
35
|
+
expect(account).toMatchObject({
|
|
36
|
+
account_id: expect.any(Number),
|
|
37
|
+
address: expect.any(String),
|
|
38
|
+
public_key: expect.any(String),
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("getSubstate", () => {
|
|
44
|
+
it("returns substate details", async () => {
|
|
45
|
+
const provider = await buildProvider();
|
|
46
|
+
const listedSubstates = await provider.listSubstates(null, null, 1, 0);
|
|
47
|
+
const firstSubstate = listedSubstates.substates[0];
|
|
48
|
+
const substate = await provider.getSubstate(firstSubstate.substate_id);
|
|
49
|
+
|
|
50
|
+
expect(substate).toMatchObject({
|
|
51
|
+
value: expect.any(Object),
|
|
52
|
+
address: {
|
|
53
|
+
substate_id: firstSubstate.substate_id,
|
|
54
|
+
version: firstSubstate.version,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("getTransactionResult", () => {
|
|
61
|
+
it("returns transaction result", async () => {
|
|
62
|
+
const provider = await buildProvider();
|
|
63
|
+
|
|
64
|
+
const id = "d5f5a26e7272b1bba7bed331179e555e28c40d92ba3cde1e9ba2b4316e50f486";
|
|
65
|
+
const txResult = await provider.getTransactionResult(id);
|
|
66
|
+
expect(txResult).toMatchObject({
|
|
67
|
+
transaction_id: id,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe("submitTransaction", () => {
|
|
73
|
+
it("submits a transaction", async () => {
|
|
74
|
+
const provider = await buildProvider();
|
|
75
|
+
|
|
76
|
+
const account = await provider.getAccount();
|
|
77
|
+
|
|
78
|
+
const fee = 2000;
|
|
79
|
+
const fee_instructions = [
|
|
80
|
+
{
|
|
81
|
+
CallMethod: {
|
|
82
|
+
component_address: account.address,
|
|
83
|
+
method: "pay_fee",
|
|
84
|
+
args: [`Amount(${fee})`]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
const request: SubmitTransactionRequest = {
|
|
90
|
+
network: 0x10, // LocalNet
|
|
91
|
+
account_id: account.account_id,
|
|
92
|
+
fee_instructions,
|
|
93
|
+
instructions: [],
|
|
94
|
+
inputs: [],
|
|
95
|
+
input_refs: [],
|
|
96
|
+
required_substates: [],
|
|
97
|
+
is_dry_run: false,
|
|
98
|
+
min_epoch: null,
|
|
99
|
+
max_epoch: null,
|
|
100
|
+
is_seal_signer_authorized: true,
|
|
101
|
+
detect_inputs_use_unversioned: true,
|
|
102
|
+
};
|
|
103
|
+
const result = await provider.submitTransaction(request);
|
|
104
|
+
|
|
105
|
+
expect(result).toMatchObject({
|
|
106
|
+
transaction_id: expect.any(String),
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe("getAccountBalances", () => {
|
|
112
|
+
it("returns account balances", async () => {
|
|
113
|
+
const provider = await buildProvider();
|
|
114
|
+
|
|
115
|
+
const account = await provider.getAccount();
|
|
116
|
+
const accountBalances = await provider.getAccountBalances(account.address);
|
|
117
|
+
|
|
118
|
+
expect(accountBalances).toHaveProperty("address");
|
|
119
|
+
|
|
120
|
+
assert(
|
|
121
|
+
accountBalances &&
|
|
122
|
+
typeof accountBalances === "object" &&
|
|
123
|
+
"balances" in accountBalances &&
|
|
124
|
+
accountBalances.balances,
|
|
125
|
+
"accountBalances is not an object",
|
|
126
|
+
);
|
|
127
|
+
assert(Array.isArray(accountBalances.balances), "accountBalances.balances is not an array");
|
|
128
|
+
expect(accountBalances.balances.length).toBeGreaterThan(0);
|
|
129
|
+
|
|
130
|
+
expect(accountBalances.balances[0]).toMatchObject({
|
|
131
|
+
balance: expect.any(Number),
|
|
132
|
+
resource_address: expect.any(String),
|
|
133
|
+
resource_type: expect.any(String),
|
|
134
|
+
token_symbol: expect.any(String),
|
|
135
|
+
vault_address: expect.any(String),
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe("getTemplateDefinition", () => {
|
|
141
|
+
it("returns template definition", async () => {
|
|
142
|
+
const provider = await buildProvider();
|
|
143
|
+
const accountTemplateAddress = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
144
|
+
const templateDefinition = await provider.getTemplateDefinition(accountTemplateAddress);
|
|
145
|
+
|
|
146
|
+
expect(templateDefinition).toMatchObject({
|
|
147
|
+
V1: {
|
|
148
|
+
functions: expect.any(Array),
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe("getPublicKey", () => {
|
|
155
|
+
it("returns public key", async () => {
|
|
156
|
+
const provider = await buildProvider();
|
|
157
|
+
const publicKey = await provider.getPublicKey("transaction", 0);
|
|
158
|
+
|
|
159
|
+
expect(publicKey).toEqual(expect.any(String));
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("listSubstates", () => {
|
|
164
|
+
it("returns substates", async () => {
|
|
165
|
+
const provider = await buildProvider();
|
|
166
|
+
const { substates } = await provider.listSubstates(null, null, 10, 0);
|
|
167
|
+
|
|
168
|
+
expect(substates.length).toBeGreaterThan(0);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("filters substates by template address", async () => {
|
|
172
|
+
const provider = await buildProvider();
|
|
173
|
+
const { substates } = await provider.listSubstates(null, null, 10, 0);
|
|
174
|
+
|
|
175
|
+
const substateWithTemplate = substates.find((substate) => substate.template_address);
|
|
176
|
+
assert(substateWithTemplate, "No substate with template found");
|
|
177
|
+
|
|
178
|
+
const templateAddress = substateWithTemplate.template_address
|
|
179
|
+
const { substates: filteredSubstates } = await provider.listSubstates(templateAddress, null, 10, 0);
|
|
180
|
+
|
|
181
|
+
expect(filteredSubstates.every((substate) => substate.template_address === templateAddress)).toBe(true);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("filters substates by type", async () => {
|
|
185
|
+
const provider = await buildProvider();
|
|
186
|
+
const { substates } = await provider.listSubstates(null, "Component", 10, 0);
|
|
187
|
+
|
|
188
|
+
expect(substates.every((substate) => substate.module_name)).toBe(true);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
language: "typescript"
|
|
2
|
+
platform: "node"
|
|
3
|
+
type: "library"
|
|
4
|
+
|
|
5
|
+
fileGroups:
|
|
6
|
+
configs:
|
|
7
|
+
- "tsconfig.json"
|
|
8
|
+
- "package.json"
|
|
9
|
+
- "eslint.config.ts"
|
|
10
|
+
sources:
|
|
11
|
+
- "src/**/*"
|
|
12
|
+
tests:
|
|
13
|
+
- "integration-tests/**/*"
|
|
14
|
+
|
|
15
|
+
tasks:
|
|
16
|
+
build:
|
|
17
|
+
command: "pnpm run build"
|
|
18
|
+
inputs:
|
|
19
|
+
- "@files(sources)"
|
|
20
|
+
- "@files(configs)"
|
|
21
|
+
outputs:
|
|
22
|
+
- "dist"
|
|
23
|
+
format:
|
|
24
|
+
command: "pnpm run format"
|
|
25
|
+
inputs:
|
|
26
|
+
- "@files(sources)"
|
|
27
|
+
- "@files(configs)"
|
|
28
|
+
- "@files(tests)"
|
|
29
|
+
options:
|
|
30
|
+
runInCI: false
|
|
31
|
+
lint:
|
|
32
|
+
command: "pnpm run lint:fix"
|
|
33
|
+
inputs:
|
|
34
|
+
- "@files(sources)"
|
|
35
|
+
- "@files(configs)"
|
|
36
|
+
- "@files(tests)"
|
|
37
|
+
options:
|
|
38
|
+
runInCI: false
|
|
39
|
+
deps:
|
|
40
|
+
- "build"
|
|
41
|
+
|
|
42
|
+
lintCheck:
|
|
43
|
+
command: "pnpm run lint"
|
|
44
|
+
inputs:
|
|
45
|
+
- "@files(sources)"
|
|
46
|
+
- "@files(configs)"
|
|
47
|
+
- "@files(tests)"
|
|
48
|
+
deps:
|
|
49
|
+
- "build"
|
|
50
|
+
formatCheck:
|
|
51
|
+
command: "pnpm run format:check"
|
|
52
|
+
inputs:
|
|
53
|
+
- "@files(sources)"
|
|
54
|
+
- "@files(configs)"
|
|
55
|
+
- "@files(tests)"
|
|
56
|
+
test:
|
|
57
|
+
command: "pnpm run integration-tests"
|
|
58
|
+
inputs:
|
|
59
|
+
- "@files(sources)"
|
|
60
|
+
- "@files(tests)"
|
|
61
|
+
- "@files(configs)"
|
|
62
|
+
deps:
|
|
63
|
+
- "build"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tari-project/tarijs",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc -b",
|
|
11
|
+
"integration-tests": "vitest run integration-tests"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@metamask/providers": "catalog:",
|
|
18
|
+
"@tari-project/metamask-provider": "workspace:^",
|
|
19
|
+
"@tari-project/tari-permissions": "workspace:^",
|
|
20
|
+
"@tari-project/tari-provider": "workspace:^",
|
|
21
|
+
"@tari-project/tari-universe-provider": "workspace:^",
|
|
22
|
+
"@tari-project/tarijs-builders": "workspace:^",
|
|
23
|
+
"@tari-project/tarijs-types": "workspace:^",
|
|
24
|
+
"@tari-project/typescript-bindings": "catalog:",
|
|
25
|
+
"@tari-project/wallet-connect-provider": "workspace:^",
|
|
26
|
+
"@tari-project/wallet-daemon-provider": "workspace:^"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "catalog:",
|
|
30
|
+
"typescript": "catalog:",
|
|
31
|
+
"vite": "catalog:",
|
|
32
|
+
"vitest": "catalog:"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"/dist"
|
|
36
|
+
],
|
|
37
|
+
"main": "dist/index.js",
|
|
38
|
+
"types": "dist/index.d.ts"
|
|
39
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { TariProvider } from "@tari-project/tari-provider";
|
|
2
|
+
import * as utils from "./utils";
|
|
3
|
+
import { Network } from "./network";
|
|
4
|
+
import {
|
|
5
|
+
Account,
|
|
6
|
+
TransactionStatus,
|
|
7
|
+
TransactionResult,
|
|
8
|
+
SubmitTransactionResponse,
|
|
9
|
+
SubmitTransactionRequest,
|
|
10
|
+
VaultBalances,
|
|
11
|
+
VaultData,
|
|
12
|
+
TemplateDefinition,
|
|
13
|
+
SubstateRequirement,
|
|
14
|
+
Substate,
|
|
15
|
+
} from "@tari-project/tari-provider";
|
|
16
|
+
import { MetamaskTariProvider } from "@tari-project/metamask-provider";
|
|
17
|
+
import { MetaMaskInpageProvider } from "@metamask/providers";
|
|
18
|
+
import {
|
|
19
|
+
WalletDaemonTariProvider,
|
|
20
|
+
WalletDaemonParameters,
|
|
21
|
+
TariPermissions,
|
|
22
|
+
} from "@tari-project/wallet-daemon-provider";
|
|
23
|
+
import { TariUniverseProvider, TariUniverseProviderParameters } from "@tari-project/tari-universe-provider";
|
|
24
|
+
import * as permissions from "@tari-project/tari-permissions";
|
|
25
|
+
import { WalletConnectTariProvider } from "@tari-project/wallet-connect-provider";
|
|
26
|
+
import {
|
|
27
|
+
TransactionBuilder,
|
|
28
|
+
TransactionRequest,
|
|
29
|
+
buildTransactionRequest,
|
|
30
|
+
submitAndWaitForTransaction,
|
|
31
|
+
waitForTransactionResult,
|
|
32
|
+
fromWorkspace,
|
|
33
|
+
toWorkspace,
|
|
34
|
+
} from "@tari-project/tarijs-builders";
|
|
35
|
+
import * as templates from "./templates";
|
|
36
|
+
|
|
37
|
+
export * from "@tari-project/tarijs-types";
|
|
38
|
+
export {
|
|
39
|
+
utils,
|
|
40
|
+
Network,
|
|
41
|
+
TariProvider,
|
|
42
|
+
Account,
|
|
43
|
+
TransactionStatus,
|
|
44
|
+
TransactionResult,
|
|
45
|
+
SubmitTransactionResponse,
|
|
46
|
+
SubmitTransactionRequest,
|
|
47
|
+
VaultBalances,
|
|
48
|
+
VaultData,
|
|
49
|
+
TemplateDefinition,
|
|
50
|
+
SubstateRequirement,
|
|
51
|
+
MetamaskTariProvider,
|
|
52
|
+
WalletDaemonTariProvider,
|
|
53
|
+
WalletDaemonParameters,
|
|
54
|
+
TariUniverseProvider,
|
|
55
|
+
TariUniverseProviderParameters,
|
|
56
|
+
TariPermissions,
|
|
57
|
+
MetaMaskInpageProvider,
|
|
58
|
+
Substate,
|
|
59
|
+
permissions,
|
|
60
|
+
WalletConnectTariProvider,
|
|
61
|
+
TransactionBuilder,
|
|
62
|
+
TransactionRequest,
|
|
63
|
+
buildTransactionRequest,
|
|
64
|
+
submitAndWaitForTransaction,
|
|
65
|
+
waitForTransactionResult,
|
|
66
|
+
fromWorkspace,
|
|
67
|
+
toWorkspace,
|
|
68
|
+
templates,
|
|
69
|
+
};
|