@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
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { sendProviderCall } from "./utils";
|
|
2
|
-
export class TariUniverseProvider {
|
|
3
|
-
params;
|
|
4
|
-
providerName = "TariUniverse";
|
|
5
|
-
__id = 0;
|
|
6
|
-
constructor(params) {
|
|
7
|
-
this.params = params;
|
|
8
|
-
const filterResizeEvent = function (event) {
|
|
9
|
-
if (event.data && event.data.type === "resize") {
|
|
10
|
-
const resizeEvent = new CustomEvent("resize", {
|
|
11
|
-
detail: { width: event.data.width, height: event.data.height },
|
|
12
|
-
});
|
|
13
|
-
window.dispatchEvent(resizeEvent);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
window.addEventListener("message", (event) => filterResizeEvent(event), false);
|
|
17
|
-
}
|
|
18
|
-
async sendRequest(req) {
|
|
19
|
-
const id = ++this.__id;
|
|
20
|
-
return sendProviderCall(req, id);
|
|
21
|
-
}
|
|
22
|
-
isConnected() {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
getPublicKey() {
|
|
26
|
-
return this.sendRequest({ methodName: "getPublicKey", args: [] });
|
|
27
|
-
}
|
|
28
|
-
async listSubstates(filter_by_template, filter_by_type, limit, offset) {
|
|
29
|
-
return this.sendRequest({
|
|
30
|
-
methodName: "listSubstates",
|
|
31
|
-
args: [filter_by_template, filter_by_type, limit, offset],
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
getConfidentialVaultBalances(viewKeyId, vaultId, min, max) {
|
|
35
|
-
return this.sendRequest({
|
|
36
|
-
methodName: "getConfidentialVaultBalances",
|
|
37
|
-
args: [viewKeyId, vaultId, min, max],
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
async createFreeTestCoins() {
|
|
41
|
-
return this.sendRequest({ methodName: "createFreeTestCoins", args: [] });
|
|
42
|
-
}
|
|
43
|
-
requestParentSize() {
|
|
44
|
-
return this.sendRequest({ methodName: "requestParentSize", args: [] });
|
|
45
|
-
}
|
|
46
|
-
async getAccount() {
|
|
47
|
-
const { account_id, address, public_key } = await this.sendRequest({ methodName: "getAccount", args: [] });
|
|
48
|
-
const { balances } = await this.getAccountBalances(address);
|
|
49
|
-
return {
|
|
50
|
-
account_id,
|
|
51
|
-
address,
|
|
52
|
-
public_key,
|
|
53
|
-
resources: balances.map((b) => ({
|
|
54
|
-
type: b.resource_type,
|
|
55
|
-
resource_address: b.resource_address,
|
|
56
|
-
balance: b.balance + b.confidential_balance,
|
|
57
|
-
vault_id: "Vault" in b.vault_address ? b.vault_address.Vault : b.vault_address,
|
|
58
|
-
token_symbol: b.token_symbol,
|
|
59
|
-
})),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
async getAccountBalances(componentAddress) {
|
|
63
|
-
return this.sendRequest({
|
|
64
|
-
methodName: "getAccountBalances",
|
|
65
|
-
args: [componentAddress],
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
async getSubstate(substate_id) {
|
|
69
|
-
return this.sendRequest({
|
|
70
|
-
methodName: "getSubstate",
|
|
71
|
-
args: [substate_id],
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
async submitTransaction(req) {
|
|
75
|
-
return this.sendRequest({
|
|
76
|
-
methodName: "submitTransaction",
|
|
77
|
-
args: [req],
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
async getTransactionResult(transactionId) {
|
|
81
|
-
return this.sendRequest({
|
|
82
|
-
methodName: "getTransactionResult",
|
|
83
|
-
args: [transactionId],
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
async getTemplateDefinition(template_address) {
|
|
87
|
-
return this.sendRequest({ methodName: "getTemplateDefinition", args: [template_address] });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export function sendProviderCall(req, id) {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
const event_ref = (resp) => {
|
|
4
|
-
if (resp.data.resultError) {
|
|
5
|
-
window.removeEventListener("message", event_ref);
|
|
6
|
-
reject(resp.data.resultError);
|
|
7
|
-
}
|
|
8
|
-
if (resp && resp.data && resp.data.id && resp.data.id === id && resp.data.type === "provider-call") {
|
|
9
|
-
window.removeEventListener("message", event_ref);
|
|
10
|
-
resolve(resp.data.result);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
window.addEventListener("message", event_ref, false);
|
|
14
|
-
window.parent.postMessage({ ...req, id, type: "provider-call" }, "*");
|
|
15
|
-
});
|
|
16
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
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
|
-
network: number;
|
|
14
|
-
account_id: number;
|
|
15
|
-
instructions: object[];
|
|
16
|
-
fee_instructions: object[];
|
|
17
|
-
inputs: object[];
|
|
18
|
-
input_refs: object[];
|
|
19
|
-
required_substates: SubstateRequirement[];
|
|
20
|
-
is_dry_run: boolean;
|
|
21
|
-
min_epoch: number | null;
|
|
22
|
-
max_epoch: number | null;
|
|
23
|
-
is_seal_signer_authorized: boolean;
|
|
24
|
-
detect_inputs_use_unversioned: boolean;
|
|
25
|
-
};
|
|
26
|
-
export type SubmitTransactionResponse = {
|
|
27
|
-
transaction_id: string;
|
|
28
|
-
};
|
|
29
|
-
export type TransactionResult = {
|
|
30
|
-
transaction_id: string;
|
|
31
|
-
status: TransactionStatus;
|
|
32
|
-
result: FinalizeResult | null;
|
|
33
|
-
};
|
|
34
|
-
export declare enum TransactionStatus {
|
|
35
|
-
New = 0,
|
|
36
|
-
DryRun = 1,
|
|
37
|
-
Pending = 2,
|
|
38
|
-
Accepted = 3,
|
|
39
|
-
Rejected = 4,
|
|
40
|
-
InvalidTransaction = 5,
|
|
41
|
-
OnlyFeeAccepted = 6
|
|
42
|
-
}
|
|
43
|
-
export interface Account {
|
|
44
|
-
account_id: number;
|
|
45
|
-
address: string;
|
|
46
|
-
public_key: string;
|
|
47
|
-
resources: VaultData[];
|
|
48
|
-
}
|
|
49
|
-
export interface VaultData {
|
|
50
|
-
type: string;
|
|
51
|
-
balance: number;
|
|
52
|
-
resource_address: string;
|
|
53
|
-
}
|
|
54
|
-
export interface VaultBalances {
|
|
55
|
-
balances: Map<string, number | null>;
|
|
56
|
-
}
|
|
57
|
-
export interface TemplateDefinition {
|
|
58
|
-
[key: string]: any;
|
|
59
|
-
}
|
|
60
|
-
export interface Substate {
|
|
61
|
-
value: any;
|
|
62
|
-
address: {
|
|
63
|
-
substate_id: string;
|
|
64
|
-
version: number;
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
export type ListSubstatesResponse = {
|
|
68
|
-
substates: Array<SubstateMetadata>;
|
|
69
|
-
};
|
package/dist/providers/types.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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 = {}));
|
|
@@ -1,43 +0,0 @@
|
|
|
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 interface WalletDaemonBaseParameters {
|
|
9
|
-
permissions: TariPermissions;
|
|
10
|
-
optionalPermissions?: TariPermissions;
|
|
11
|
-
onConnection?: () => void;
|
|
12
|
-
}
|
|
13
|
-
export interface WalletDaemonParameters extends WalletDaemonBaseParameters {
|
|
14
|
-
signalingServerUrl?: string;
|
|
15
|
-
webRtcConfig?: RTCConfiguration;
|
|
16
|
-
name?: string;
|
|
17
|
-
}
|
|
18
|
-
export interface WalletDaemonFetchParameters extends WalletDaemonBaseParameters {
|
|
19
|
-
serverUrl: string;
|
|
20
|
-
}
|
|
21
|
-
export declare class WalletDaemonTariProvider implements TariProvider {
|
|
22
|
-
providerName: string;
|
|
23
|
-
params: WalletDaemonParameters;
|
|
24
|
-
client: WalletDaemonClient;
|
|
25
|
-
private constructor();
|
|
26
|
-
static build(params: WalletDaemonParameters): Promise<WalletDaemonTariProvider>;
|
|
27
|
-
static buildFetchProvider(params: WalletDaemonFetchParameters): Promise<WalletDaemonTariProvider>;
|
|
28
|
-
private static buildPermissions;
|
|
29
|
-
private getWebRtcTransport;
|
|
30
|
-
get token(): string | undefined;
|
|
31
|
-
get tokenUrl(): string | undefined;
|
|
32
|
-
isConnected(): boolean;
|
|
33
|
-
createFreeTestCoins(): Promise<Account>;
|
|
34
|
-
getAccount(): Promise<Account>;
|
|
35
|
-
getAccountBalances(componentAddress: string): Promise<unknown>;
|
|
36
|
-
getSubstate(substateId: string): Promise<Substate>;
|
|
37
|
-
submitTransaction(req: SubmitTransactionRequest): Promise<SubmitTransactionResponse>;
|
|
38
|
-
getTransactionResult(transactionId: string): Promise<TransactionResult>;
|
|
39
|
-
getPublicKey(branch: string, index: number): Promise<string>;
|
|
40
|
-
getTemplateDefinition(template_address: string): Promise<TemplateDefinition>;
|
|
41
|
-
getConfidentialVaultBalances(viewKeyId: number, vaultId: string, min?: number | null, max?: number | null): Promise<VaultBalances>;
|
|
42
|
-
listSubstates(filter_by_template: string | null, filter_by_type: SubstateType | null, limit: number | null, offset: number | null): Promise<ListSubstatesResponse>;
|
|
43
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import { TariPermissions, } from "./tari_permissions";
|
|
2
|
-
import { TariConnection } from "./webrtc";
|
|
3
|
-
import { TransactionStatus, } from "../types";
|
|
4
|
-
import { WalletDaemonClient, 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
|
-
;
|
|
9
|
-
export class WalletDaemonTariProvider {
|
|
10
|
-
providerName = "WalletDaemon";
|
|
11
|
-
params;
|
|
12
|
-
client;
|
|
13
|
-
constructor(params, connection) {
|
|
14
|
-
this.params = params;
|
|
15
|
-
this.client = connection;
|
|
16
|
-
}
|
|
17
|
-
static async build(params) {
|
|
18
|
-
const allPermissions = WalletDaemonTariProvider.buildPermissions(params);
|
|
19
|
-
let connection = new TariConnection(params.signalingServerUrl, params.webRtcConfig);
|
|
20
|
-
const client = WalletDaemonClient.new(WebRtcRpcTransport.new(connection));
|
|
21
|
-
await connection.init(allPermissions, (conn) => {
|
|
22
|
-
params.onConnection?.();
|
|
23
|
-
if (conn.token) {
|
|
24
|
-
client.setToken(conn.token);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
return new WalletDaemonTariProvider(params, client);
|
|
28
|
-
}
|
|
29
|
-
static async buildFetchProvider(params) {
|
|
30
|
-
const allPermissions = WalletDaemonTariProvider.buildPermissions(params);
|
|
31
|
-
const client = WalletDaemonClient.usingFetchTransport(params.serverUrl);
|
|
32
|
-
const plainPermissions = allPermissions.toJSON().flatMap((p) => typeof (p) === "string" ? [p] : []);
|
|
33
|
-
const authResponse = await client.authRequest(plainPermissions);
|
|
34
|
-
await client.authAccept(authResponse, "WalletDaemon");
|
|
35
|
-
params.onConnection?.();
|
|
36
|
-
return new WalletDaemonTariProvider(params, client);
|
|
37
|
-
}
|
|
38
|
-
static buildPermissions(params) {
|
|
39
|
-
const allPermissions = new TariPermissions();
|
|
40
|
-
allPermissions.addPermissions(params.permissions);
|
|
41
|
-
if (params.optionalPermissions) {
|
|
42
|
-
allPermissions.addPermissions(params.optionalPermissions);
|
|
43
|
-
}
|
|
44
|
-
return allPermissions;
|
|
45
|
-
}
|
|
46
|
-
getWebRtcTransport() {
|
|
47
|
-
const transport = this.client.getTransport();
|
|
48
|
-
return transport instanceof WebRtcRpcTransport ? transport : undefined;
|
|
49
|
-
}
|
|
50
|
-
get token() {
|
|
51
|
-
return this.getWebRtcTransport()?.token();
|
|
52
|
-
}
|
|
53
|
-
get tokenUrl() {
|
|
54
|
-
if (!this.token) {
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
const name = this.params.name && encodeURIComponent(this.params.name) || '';
|
|
58
|
-
const token = this.token;
|
|
59
|
-
const permissions = JSON.stringify(this.params.permissions);
|
|
60
|
-
const optionalPermissions = JSON.stringify(this.params.optionalPermissions);
|
|
61
|
-
return `tari://${name}/${token}/${permissions}/${optionalPermissions}`;
|
|
62
|
-
}
|
|
63
|
-
isConnected() {
|
|
64
|
-
return this.getWebRtcTransport()?.isConnected() || true;
|
|
65
|
-
}
|
|
66
|
-
async createFreeTestCoins() {
|
|
67
|
-
const res = await this.client.createFreeTestCoins({
|
|
68
|
-
account: { Name: "template_web" },
|
|
69
|
-
amount: 1000000,
|
|
70
|
-
max_fee: null,
|
|
71
|
-
key_id: 0
|
|
72
|
-
});
|
|
73
|
-
return {
|
|
74
|
-
account_id: res.account.key_index,
|
|
75
|
-
address: res.account.address.Component,
|
|
76
|
-
public_key: res.public_key,
|
|
77
|
-
resources: []
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
async getAccount() {
|
|
81
|
-
const { account, public_key } = await this.client.accountsGetDefault({});
|
|
82
|
-
const address = typeof account.address === "object" ? account.address.Component : account.address;
|
|
83
|
-
const { balances } = await this.client.accountsGetBalances({ account: { ComponentAddress: address }, refresh: false });
|
|
84
|
-
return {
|
|
85
|
-
account_id: account.key_index,
|
|
86
|
-
address,
|
|
87
|
-
public_key,
|
|
88
|
-
// TODO: should be vaults not resources
|
|
89
|
-
resources: balances.map((b) => ({
|
|
90
|
-
type: b.resource_type,
|
|
91
|
-
resource_address: b.resource_address,
|
|
92
|
-
balance: b.balance + b.confidential_balance,
|
|
93
|
-
vault_id: (typeof (b.vault_address) === "object" && 'Vault' in b.vault_address) ? b.vault_address.Vault : b.vault_address,
|
|
94
|
-
token_symbol: b.token_symbol,
|
|
95
|
-
}))
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
async getAccountBalances(componentAddress) {
|
|
99
|
-
return await this.client.accountsGetBalances({ account: { ComponentAddress: componentAddress }, refresh: true });
|
|
100
|
-
}
|
|
101
|
-
async getSubstate(substateId) {
|
|
102
|
-
// Wallet daemon expects a SubstateId as a string
|
|
103
|
-
const { value, record } = await this.client.substatesGet({ substate_id: substateId });
|
|
104
|
-
return {
|
|
105
|
-
value,
|
|
106
|
-
address: {
|
|
107
|
-
substate_id: substateIdToString(record.substate_id),
|
|
108
|
-
version: record.version
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
async submitTransaction(req) {
|
|
113
|
-
const params = {
|
|
114
|
-
transaction: {
|
|
115
|
-
V1: {
|
|
116
|
-
network: req.network,
|
|
117
|
-
instructions: req.instructions,
|
|
118
|
-
fee_instructions: req.fee_instructions,
|
|
119
|
-
inputs: req.required_substates.map((s) => ({
|
|
120
|
-
// TODO: Hmm The bindings want a SubstateId object, but the wallet only wants a string. Any is used to skip type checking here
|
|
121
|
-
substate_id: s.substate_id,
|
|
122
|
-
version: s.version ?? null,
|
|
123
|
-
})),
|
|
124
|
-
min_epoch: null,
|
|
125
|
-
max_epoch: null,
|
|
126
|
-
is_seal_signer_authorized: req.is_seal_signer_authorized,
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
signing_key_index: req.account_id,
|
|
130
|
-
autofill_inputs: [],
|
|
131
|
-
detect_inputs: true,
|
|
132
|
-
proof_ids: [],
|
|
133
|
-
detect_inputs_use_unversioned: req.detect_inputs_use_unversioned,
|
|
134
|
-
};
|
|
135
|
-
const res = await this.client.submitTransaction(params);
|
|
136
|
-
return { transaction_id: res.transaction_id };
|
|
137
|
-
}
|
|
138
|
-
async getTransactionResult(transactionId) {
|
|
139
|
-
const res = await this.client.getTransactionResult({ transaction_id: transactionId });
|
|
140
|
-
return {
|
|
141
|
-
transaction_id: transactionId,
|
|
142
|
-
status: convertStringToTransactionStatus(res.status),
|
|
143
|
-
result: res.result,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
async getPublicKey(branch, index) {
|
|
147
|
-
const res = await this.client.createKey({ branch: branch, specific_index: index });
|
|
148
|
-
return res.public_key;
|
|
149
|
-
}
|
|
150
|
-
async getTemplateDefinition(template_address) {
|
|
151
|
-
let resp = await this.client.templatesGet({ template_address });
|
|
152
|
-
return resp.template_definition;
|
|
153
|
-
}
|
|
154
|
-
async getConfidentialVaultBalances(viewKeyId, vaultId, min = null, max = null) {
|
|
155
|
-
const res = await this.client.viewVaultBalance({
|
|
156
|
-
view_key_id: viewKeyId,
|
|
157
|
-
vault_id: vaultId,
|
|
158
|
-
minimum_expected_value: min,
|
|
159
|
-
maximum_expected_value: max,
|
|
160
|
-
});
|
|
161
|
-
return { balances: res.balances };
|
|
162
|
-
}
|
|
163
|
-
async listSubstates(filter_by_template, filter_by_type, limit, offset) {
|
|
164
|
-
const resp = await this.client.substatesList({
|
|
165
|
-
filter_by_template,
|
|
166
|
-
filter_by_type,
|
|
167
|
-
limit,
|
|
168
|
-
offset
|
|
169
|
-
});
|
|
170
|
-
const substates = resp.substates.map((s) => ({
|
|
171
|
-
substate_id: typeof s.substate_id === "string" ? s.substate_id : substateIdToString(s.substate_id),
|
|
172
|
-
module_name: s.module_name,
|
|
173
|
-
version: s.version,
|
|
174
|
-
template_address: s.template_address,
|
|
175
|
-
}));
|
|
176
|
-
return { substates };
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
function convertStringToTransactionStatus(status) {
|
|
180
|
-
switch (status) {
|
|
181
|
-
case "New":
|
|
182
|
-
return TransactionStatus.New;
|
|
183
|
-
case "DryRun":
|
|
184
|
-
return TransactionStatus.DryRun;
|
|
185
|
-
case "Pending":
|
|
186
|
-
return TransactionStatus.Pending;
|
|
187
|
-
case "Accepted":
|
|
188
|
-
return TransactionStatus.Accepted;
|
|
189
|
-
case "Rejected":
|
|
190
|
-
return TransactionStatus.Rejected;
|
|
191
|
-
case "InvalidTransaction":
|
|
192
|
-
return TransactionStatus.InvalidTransaction;
|
|
193
|
-
case "OnlyFeeAccepted":
|
|
194
|
-
return TransactionStatus.OnlyFeeAccepted;
|
|
195
|
-
default:
|
|
196
|
-
throw new Error(`Unknown status: ${status}`);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
export declare class Hash {
|
|
2
|
-
private value;
|
|
3
|
-
constructor(value: number[]);
|
|
4
|
-
toJSON(): number[];
|
|
5
|
-
}
|
|
6
|
-
export declare enum TAG {
|
|
7
|
-
ComponentAddress = 128,
|
|
8
|
-
Metadata = 129,
|
|
9
|
-
NonFungibleAddress = 130,
|
|
10
|
-
ResourceAddress = 131,
|
|
11
|
-
VaultId = 132,
|
|
12
|
-
TransactionReceipt = 134,
|
|
13
|
-
FeeClaim = 135
|
|
14
|
-
}
|
|
15
|
-
export declare class Tagged {
|
|
16
|
-
private value;
|
|
17
|
-
private tag;
|
|
18
|
-
constructor(tag: number, value: any);
|
|
19
|
-
toJSON(): {
|
|
20
|
-
"@@TAGGED@@": any[];
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export declare class ResourceAddress {
|
|
24
|
-
private tagged;
|
|
25
|
-
constructor(hash: Hash);
|
|
26
|
-
toJSON(): {
|
|
27
|
-
"@@TAGGED@@": any[];
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
export declare class UnclaimedConfidentialOutputAddress {
|
|
31
|
-
private hash;
|
|
32
|
-
constructor(hash: Hash);
|
|
33
|
-
toJSON(): number[];
|
|
34
|
-
}
|
|
35
|
-
export type u64 = number;
|
|
36
|
-
export type u32 = number;
|
|
37
|
-
export declare class U256 {
|
|
38
|
-
private value;
|
|
39
|
-
constructor(value: number[]);
|
|
40
|
-
toJSON(): number[];
|
|
41
|
-
}
|
|
42
|
-
export type NonFungibleIdType = u32 | u64 | string | U256;
|
|
43
|
-
export declare class NonFungibleId {
|
|
44
|
-
private value;
|
|
45
|
-
constructor(value: NonFungibleIdType);
|
|
46
|
-
toJSON(): {
|
|
47
|
-
string: string;
|
|
48
|
-
Uint64?: undefined;
|
|
49
|
-
U256?: undefined;
|
|
50
|
-
} | {
|
|
51
|
-
Uint64: number;
|
|
52
|
-
string?: undefined;
|
|
53
|
-
U256?: undefined;
|
|
54
|
-
} | {
|
|
55
|
-
U256: U256;
|
|
56
|
-
string?: undefined;
|
|
57
|
-
Uint64?: undefined;
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
export declare class NonFungibleAddressContents {
|
|
61
|
-
private resource_address;
|
|
62
|
-
private id;
|
|
63
|
-
constructor(resource_address: ResourceAddress, id: NonFungibleId);
|
|
64
|
-
toJSON(): {
|
|
65
|
-
resource_address: ResourceAddress;
|
|
66
|
-
id: NonFungibleId;
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
export declare class NonFungibleAddress {
|
|
70
|
-
private tagged;
|
|
71
|
-
constructor(value: NonFungibleAddressContents);
|
|
72
|
-
toJSON(): {
|
|
73
|
-
"@@TAGGED@@": any[];
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
export declare class NonFungibleIndexAddress {
|
|
77
|
-
private resource_address;
|
|
78
|
-
private index;
|
|
79
|
-
constructor(resource_address: ResourceAddress, index: number);
|
|
80
|
-
toJSON(): {
|
|
81
|
-
resource_address: ResourceAddress;
|
|
82
|
-
index: number;
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
export declare class ComponentAddress {
|
|
86
|
-
private tagged;
|
|
87
|
-
constructor(hash: Hash);
|
|
88
|
-
toJSON(): {
|
|
89
|
-
"@@TAGGED@@": any[];
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
export declare class VaultId {
|
|
93
|
-
private tagged;
|
|
94
|
-
constructor(hash: Hash);
|
|
95
|
-
toJSON(): {
|
|
96
|
-
"@@TAGGED@@": any[];
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
export type SubstateAddressType = ResourceAddress | ComponentAddress | VaultId | UnclaimedConfidentialOutputAddress | NonFungibleAddress | NonFungibleIndexAddress;
|
|
100
|
-
export declare class SubstateAddress {
|
|
101
|
-
private value;
|
|
102
|
-
constructor(value: SubstateAddressType);
|
|
103
|
-
toJSON(): {
|
|
104
|
-
Component: ComponentAddress;
|
|
105
|
-
Resource?: undefined;
|
|
106
|
-
Vault?: undefined;
|
|
107
|
-
UnclaimedConfidentialOutput?: undefined;
|
|
108
|
-
NonFungible?: undefined;
|
|
109
|
-
NonFungibleIndex?: undefined;
|
|
110
|
-
} | {
|
|
111
|
-
Resource: ResourceAddress;
|
|
112
|
-
Component?: undefined;
|
|
113
|
-
Vault?: undefined;
|
|
114
|
-
UnclaimedConfidentialOutput?: undefined;
|
|
115
|
-
NonFungible?: undefined;
|
|
116
|
-
NonFungibleIndex?: undefined;
|
|
117
|
-
} | {
|
|
118
|
-
Vault: VaultId;
|
|
119
|
-
Component?: undefined;
|
|
120
|
-
Resource?: undefined;
|
|
121
|
-
UnclaimedConfidentialOutput?: undefined;
|
|
122
|
-
NonFungible?: undefined;
|
|
123
|
-
NonFungibleIndex?: undefined;
|
|
124
|
-
} | {
|
|
125
|
-
UnclaimedConfidentialOutput: UnclaimedConfidentialOutputAddress;
|
|
126
|
-
Component?: undefined;
|
|
127
|
-
Resource?: undefined;
|
|
128
|
-
Vault?: undefined;
|
|
129
|
-
NonFungible?: undefined;
|
|
130
|
-
NonFungibleIndex?: undefined;
|
|
131
|
-
} | {
|
|
132
|
-
NonFungible: NonFungibleAddress;
|
|
133
|
-
Component?: undefined;
|
|
134
|
-
Resource?: undefined;
|
|
135
|
-
Vault?: undefined;
|
|
136
|
-
UnclaimedConfidentialOutput?: undefined;
|
|
137
|
-
NonFungibleIndex?: undefined;
|
|
138
|
-
} | {
|
|
139
|
-
NonFungibleIndex: NonFungibleIndexAddress;
|
|
140
|
-
Component?: undefined;
|
|
141
|
-
Resource?: undefined;
|
|
142
|
-
Vault?: undefined;
|
|
143
|
-
UnclaimedConfidentialOutput?: undefined;
|
|
144
|
-
NonFungible?: undefined;
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
export declare class TariPermissionAccountBalance {
|
|
148
|
-
private value;
|
|
149
|
-
constructor(value: SubstateAddress);
|
|
150
|
-
toJSON(): {
|
|
151
|
-
AccountBalance: SubstateAddress;
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
export declare class TariPermissionAccountInfo {
|
|
155
|
-
constructor();
|
|
156
|
-
toJSON(): string;
|
|
157
|
-
}
|
|
158
|
-
export declare class TariPermissionAccountList {
|
|
159
|
-
private value?;
|
|
160
|
-
constructor(value?: ComponentAddress);
|
|
161
|
-
toJSON(): {
|
|
162
|
-
AccountList: ComponentAddress | null;
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
export declare class TariPermissionKeyList {
|
|
166
|
-
constructor();
|
|
167
|
-
toJSON(): string;
|
|
168
|
-
}
|
|
169
|
-
export declare class TariPermissionTransactionGet {
|
|
170
|
-
constructor();
|
|
171
|
-
toJSON(): string;
|
|
172
|
-
}
|
|
173
|
-
export declare class TariPermissionTransactionSend {
|
|
174
|
-
private value?;
|
|
175
|
-
constructor(value?: SubstateAddress);
|
|
176
|
-
toJSON(): {
|
|
177
|
-
TransactionSend: null;
|
|
178
|
-
} | {
|
|
179
|
-
TransactionSend: SubstateAddress;
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
export declare class TariPermissionGetNft {
|
|
183
|
-
private value0?;
|
|
184
|
-
private value1?;
|
|
185
|
-
constructor(value0?: SubstateAddress, value1?: ResourceAddress);
|
|
186
|
-
toJSON(): {
|
|
187
|
-
GetNft: (ResourceAddress | SubstateAddress | undefined)[];
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
export declare class TariPermissionNftGetOwnershipProof {
|
|
191
|
-
private value?;
|
|
192
|
-
constructor(value?: ResourceAddress);
|
|
193
|
-
toJSON(): {
|
|
194
|
-
NftGetOwnershipProof: ResourceAddress | undefined;
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
export declare class TariPermissionTransactionsGet {
|
|
198
|
-
constructor();
|
|
199
|
-
toJSON(): string;
|
|
200
|
-
}
|
|
201
|
-
export declare class TariPermissionSubstatesRead {
|
|
202
|
-
constructor();
|
|
203
|
-
toJSON(): string;
|
|
204
|
-
}
|
|
205
|
-
export declare class TariPermissionTemplatesRead {
|
|
206
|
-
constructor();
|
|
207
|
-
toJSON(): string;
|
|
208
|
-
}
|
|
209
|
-
export type TariPermission = TariPermissionNftGetOwnershipProof | TariPermissionAccountBalance | TariPermissionAccountInfo | TariPermissionAccountList | TariPermissionKeyList | TariPermissionTransactionGet | TariPermissionTransactionSend | TariPermissionGetNft | TariPermissionTransactionsGet | TariPermissionSubstatesRead | TariPermissionTemplatesRead | string;
|
|
210
|
-
export declare class TariPermissions {
|
|
211
|
-
private permissions;
|
|
212
|
-
constructor();
|
|
213
|
-
addPermission(permission: TariPermission): this;
|
|
214
|
-
addPermissions(other: TariPermissions): this;
|
|
215
|
-
toJSON(): TariPermission[];
|
|
216
|
-
}
|