@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.
- package/dist/builders/helpers/index.d.ts +2 -0
- package/dist/builders/helpers/index.js +2 -0
- package/dist/builders/helpers/submitTransaction.d.ts +13 -0
- package/dist/builders/helpers/submitTransaction.js +59 -0
- package/dist/builders/helpers/workspace.d.ts +23 -0
- package/dist/builders/helpers/workspace.js +29 -0
- package/dist/builders/index.d.ts +3 -0
- package/dist/builders/index.js +3 -0
- package/dist/builders/transaction/TransactionBuilder.d.ts +44 -0
- package/dist/builders/transaction/TransactionBuilder.js +164 -0
- package/dist/builders/transaction/TransactionRequest.d.ts +27 -0
- package/dist/builders/transaction/TransactionRequest.js +67 -0
- package/dist/builders/transaction/index.d.ts +2 -0
- package/dist/builders/transaction/index.js +2 -0
- package/dist/builders/types/Amount.d.ts +23 -0
- package/dist/builders/types/Amount.js +93 -0
- package/dist/builders/types/Arg.d.ts +1 -0
- package/dist/builders/types/Arg.js +1 -0
- package/dist/builders/types/Builder.d.ts +47 -0
- package/dist/builders/types/Builder.js +1 -0
- package/dist/builders/types/ComponentAddress.d.ts +1 -0
- package/dist/builders/types/ComponentAddress.js +1 -0
- package/dist/builders/types/ConfidentialClaim.d.ts +8 -0
- package/dist/builders/types/ConfidentialClaim.js +1 -0
- package/dist/builders/types/ConfidentialOutput.d.ts +8 -0
- package/dist/builders/types/ConfidentialOutput.js +1 -0
- package/dist/builders/types/ConfidentialOutputStatement.d.ts +9 -0
- package/dist/builders/types/ConfidentialOutputStatement.js +1 -0
- package/dist/builders/types/ConfidentialStatement.d.ts +8 -0
- package/dist/builders/types/ConfidentialStatement.js +1 -0
- package/dist/builders/types/ConfidentialWithdrawProof.d.ts +7 -0
- package/dist/builders/types/ConfidentialWithdrawProof.js +1 -0
- package/dist/builders/types/ElgamalVerifiableBalance.d.ts +4 -0
- package/dist/builders/types/ElgamalVerifiableBalance.js +1 -0
- package/dist/builders/types/Epoch.d.ts +1 -0
- package/dist/builders/types/Epoch.js +1 -0
- package/dist/builders/types/FinalizeResult.d.ts +20 -0
- package/dist/builders/types/FinalizeResult.js +1 -0
- package/dist/builders/types/Instruction.d.ts +56 -0
- package/dist/builders/types/Instruction.js +1 -0
- package/dist/builders/types/ResourceAddress.d.ts +1 -0
- package/dist/builders/types/ResourceAddress.js +2 -0
- package/dist/builders/types/SubstateDiff.d.ts +7 -0
- package/dist/builders/types/SubstateDiff.js +1 -0
- package/dist/builders/types/SubstateRequirement.d.ts +5 -0
- package/dist/builders/types/SubstateRequirement.js +1 -0
- package/dist/builders/types/TemplateAddress.d.ts +1 -0
- package/dist/builders/types/TemplateAddress.js +2 -0
- package/dist/builders/types/Transaction.d.ts +15 -0
- package/dist/builders/types/Transaction.js +1 -0
- package/dist/builders/types/TransactionId.d.ts +1 -0
- package/dist/builders/types/TransactionId.js +1 -0
- package/dist/builders/types/TransactionResult.d.ts +22 -0
- package/dist/builders/types/TransactionResult.js +10 -0
- package/dist/builders/types/TransactionSignature.d.ts +4 -0
- package/dist/builders/types/TransactionSignature.js +1 -0
- package/dist/builders/types/UnsignedTransaction.d.ts +12 -0
- package/dist/builders/types/UnsignedTransaction.js +1 -0
- package/dist/builders/types/VersionedSubstateId.d.ts +5 -0
- package/dist/builders/types/VersionedSubstateId.js +1 -0
- package/dist/builders/types/ViewableBalanceProof.d.ts +10 -0
- package/dist/builders/types/ViewableBalanceProof.js +2 -0
- package/dist/builders/types/Workspace.d.ts +3 -0
- package/dist/builders/types/Workspace.js +1 -0
- package/dist/builders/types/index.d.ts +24 -0
- package/dist/builders/types/index.js +2 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +12 -0
- package/dist/providers/index.d.ts +16 -0
- package/dist/providers/index.js +1 -0
- package/dist/providers/metamask/index.d.ts +30 -0
- package/dist/providers/metamask/index.js +169 -0
- package/dist/providers/metamask/utils.d.ts +38 -0
- package/dist/providers/metamask/utils.js +55 -0
- package/dist/providers/tari_universe/index.d.ts +3 -0
- package/dist/providers/tari_universe/index.js +3 -0
- package/dist/providers/tari_universe/provider.d.ts +23 -0
- package/dist/providers/tari_universe/provider.js +88 -0
- package/dist/providers/tari_universe/types.d.ts +30 -0
- package/dist/providers/tari_universe/types.js +1 -0
- package/dist/providers/types.d.ts +66 -0
- package/dist/providers/types.js +10 -0
- package/dist/providers/wallet_daemon/index.d.ts +3 -0
- package/dist/providers/wallet_daemon/index.js +3 -0
- package/dist/providers/wallet_daemon/provider.d.ts +35 -0
- package/dist/providers/wallet_daemon/provider.js +173 -0
- package/dist/providers/wallet_daemon/tari_permissions.d.ts +216 -0
- package/dist/providers/wallet_daemon/tari_permissions.js +282 -0
- package/dist/providers/wallet_daemon/webrtc.d.ts +20 -0
- package/dist/providers/wallet_daemon/webrtc.js +201 -0
- package/dist/providers/wallet_daemon/webrtc_transport.d.ts +10 -0
- package/dist/providers/wallet_daemon/webrtc_transport.js +18 -0
- package/dist/providers/walletconnect/index.d.ts +23 -0
- package/dist/providers/walletconnect/index.js +217 -0
- package/dist/templates/Account.d.ts +65 -0
- package/dist/templates/Account.js +31 -0
- package/dist/templates/Pool.d.ts +30 -0
- package/dist/templates/Pool.js +20 -0
- package/dist/templates/Tariswap.d.ts +65 -0
- package/dist/templates/Tariswap.js +36 -0
- package/dist/templates/TemplateFactory.d.ts +9 -0
- package/dist/templates/TemplateFactory.js +18 -0
- package/dist/templates/TestFaucet.d.ts +49 -0
- package/dist/templates/TestFaucet.js +31 -0
- package/dist/templates/index.d.ts +4 -0
- package/dist/templates/index.js +4 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +22 -0
- package/package.json +8 -4
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Amount } from "./Amount";
|
|
2
|
+
import type { ConfidentialStatement } from "./ConfidentialStatement";
|
|
3
|
+
export interface ConfidentialOutputStatement {
|
|
4
|
+
outputStatement?: ConfidentialStatement;
|
|
5
|
+
changeStatement?: ConfidentialStatement;
|
|
6
|
+
rangeProof: Array<number>;
|
|
7
|
+
outputRevealedAmount: Amount;
|
|
8
|
+
changeRevealedAmount: Amount;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ViewableBalanceProof } from "./ViewableBalanceProof";
|
|
2
|
+
export interface ConfidentialStatement {
|
|
3
|
+
commitment: Array<number>;
|
|
4
|
+
senderPublicNonce: Array<number>;
|
|
5
|
+
encryptedData: Array<number>;
|
|
6
|
+
minimumValuePromise: number;
|
|
7
|
+
viewableBalanceProof?: ViewableBalanceProof;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Epoch = number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FeeReceipt, InstructionResult, LogEntry, RejectReason } from "@tari-project/typescript-bindings";
|
|
2
|
+
import { SubstateDiff } from "./SubstateDiff";
|
|
3
|
+
export type TxResultAccept = {
|
|
4
|
+
Accept: SubstateDiff;
|
|
5
|
+
};
|
|
6
|
+
export type TxResultAcceptFeeRejectRest = {
|
|
7
|
+
AcceptFeeRejectRest: [SubstateDiff, RejectReason];
|
|
8
|
+
};
|
|
9
|
+
export type TxResultReject = {
|
|
10
|
+
Reject: RejectReason;
|
|
11
|
+
};
|
|
12
|
+
export type FinalizeResultStatus = TxResultAccept | TxResultAcceptFeeRejectRest | TxResultReject;
|
|
13
|
+
export interface FinalizeResult {
|
|
14
|
+
transaction_hash: Uint8Array;
|
|
15
|
+
events: Array<Event>;
|
|
16
|
+
logs: Array<LogEntry>;
|
|
17
|
+
execution_results: Array<InstructionResult>;
|
|
18
|
+
result: FinalizeResultStatus;
|
|
19
|
+
fee_receipt: FeeReceipt;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ComponentAddress, LogLevel } from "@tari-project/typescript-bindings";
|
|
2
|
+
import { Arg } from "./Arg";
|
|
3
|
+
import { ConfidentialClaim } from "./ConfidentialClaim";
|
|
4
|
+
import { Amount } from "./Amount";
|
|
5
|
+
import { ConfidentialOutput } from "./ConfidentialOutput";
|
|
6
|
+
import { TemplateAddress } from "./TemplateAddress";
|
|
7
|
+
export type Instruction = CreateAccount | CallFunction | CallMethod | PutLastInstructionOutputOnWorkspace | EmitLog | ClaimBurn | ClaimValidatorFees | DropAllProofsInWorkspace | CreateFreeTestCoins;
|
|
8
|
+
export type CreateAccount = {
|
|
9
|
+
CreateAccount: {
|
|
10
|
+
owner_public_key: string;
|
|
11
|
+
workspace_bucket: string | null;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type CallFunction = {
|
|
15
|
+
CallFunction: {
|
|
16
|
+
template_address: TemplateAddress;
|
|
17
|
+
function: string;
|
|
18
|
+
args: Array<Arg>;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export type CallMethod = {
|
|
22
|
+
CallMethod: {
|
|
23
|
+
component_address: ComponentAddress;
|
|
24
|
+
method: string;
|
|
25
|
+
args: Array<Arg>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export type PutLastInstructionOutputOnWorkspace = {
|
|
29
|
+
PutLastInstructionOutputOnWorkspace: {
|
|
30
|
+
key: number[];
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type EmitLog = {
|
|
34
|
+
EmitLog: {
|
|
35
|
+
level: LogLevel;
|
|
36
|
+
message: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export type ClaimBurn = {
|
|
40
|
+
ClaimBurn: {
|
|
41
|
+
claim: ConfidentialClaim;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export type ClaimValidatorFees = {
|
|
45
|
+
ClaimValidatorFees: {
|
|
46
|
+
epoch: number;
|
|
47
|
+
validator_public_key: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export type DropAllProofsInWorkspace = "DropAllProofsInWorkspace";
|
|
51
|
+
export type CreateFreeTestCoins = {
|
|
52
|
+
CreateFreeTestCoins: {
|
|
53
|
+
revealed_amount: Amount;
|
|
54
|
+
output: ConfidentialOutput | null;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ResourceAddress = string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Substate, SubstateId } from "@tari-project/typescript-bindings";
|
|
2
|
+
export type UpSubstates = Array<[SubstateId, Substate]>;
|
|
3
|
+
export type DownSubstates = Array<[SubstateId, number]>;
|
|
4
|
+
export interface SubstateDiff {
|
|
5
|
+
up_substates: UpSubstates;
|
|
6
|
+
down_substates: DownSubstates;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TemplateAddress = string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TransactionSignature } from "@tari-project/typescript-bindings";
|
|
2
|
+
import { Instruction } from "./Instruction";
|
|
3
|
+
import { SubstateRequirement } from "./SubstateRequirement";
|
|
4
|
+
import { Epoch } from "./Epoch";
|
|
5
|
+
import { VersionedSubstateId } from "./VersionedSubstateId";
|
|
6
|
+
export interface Transaction {
|
|
7
|
+
id: string;
|
|
8
|
+
feeInstructions: Array<Instruction>;
|
|
9
|
+
instructions: Array<Instruction>;
|
|
10
|
+
inputs: Array<SubstateRequirement>;
|
|
11
|
+
minEpoch?: Epoch;
|
|
12
|
+
maxEpoch?: Epoch;
|
|
13
|
+
signatures: Array<TransactionSignature>;
|
|
14
|
+
filledInputs: Array<VersionedSubstateId>;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TransactionId = string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FinalizeResult } from "./FinalizeResult";
|
|
2
|
+
export type SubmitTransactionResponse = {
|
|
3
|
+
transaction_id: string;
|
|
4
|
+
};
|
|
5
|
+
export interface SubmitTxResult {
|
|
6
|
+
response: SubmitTransactionResponse;
|
|
7
|
+
result: TransactionResult;
|
|
8
|
+
}
|
|
9
|
+
export declare enum TransactionStatus {
|
|
10
|
+
New = 0,
|
|
11
|
+
DryRun = 1,
|
|
12
|
+
Pending = 2,
|
|
13
|
+
Accepted = 3,
|
|
14
|
+
Rejected = 4,
|
|
15
|
+
InvalidTransaction = 5,
|
|
16
|
+
OnlyFeeAccepted = 6
|
|
17
|
+
}
|
|
18
|
+
export type TransactionResult = {
|
|
19
|
+
transaction_id: string;
|
|
20
|
+
status: TransactionStatus;
|
|
21
|
+
result: FinalizeResult | null;
|
|
22
|
+
};
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Instruction } from "./Instruction";
|
|
2
|
+
import { Epoch } from "./Epoch";
|
|
3
|
+
import { SubstateRequirement } from "./SubstateRequirement";
|
|
4
|
+
import { VersionedSubstateId } from "./VersionedSubstateId";
|
|
5
|
+
export interface UnsignedTransaction {
|
|
6
|
+
feeInstructions: Instruction[];
|
|
7
|
+
instructions: Instruction[];
|
|
8
|
+
inputs: SubstateRequirement[];
|
|
9
|
+
filledInputs: VersionedSubstateId[];
|
|
10
|
+
minEpoch?: Epoch;
|
|
11
|
+
maxEpoch?: Epoch;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { Builder, TariCreateAccountDefinition, TariFunctionDefinition, TariMethodDefinition, TransactionConstructor, } from "./Builder";
|
|
2
|
+
export { TemplateAddress } from "./TemplateAddress";
|
|
3
|
+
export { Amount } from "./Amount";
|
|
4
|
+
export { Arg } from "./Arg";
|
|
5
|
+
export { ComponentAddress } from "./ComponentAddress";
|
|
6
|
+
export { ConfidentialClaim } from "./ConfidentialClaim";
|
|
7
|
+
export { ConfidentialOutput } from "./ConfidentialOutput";
|
|
8
|
+
export { ConfidentialOutputStatement } from "./ConfidentialOutputStatement";
|
|
9
|
+
export { ConfidentialStatement } from "./ConfidentialStatement";
|
|
10
|
+
export { ConfidentialWithdrawProof } from "./ConfidentialWithdrawProof";
|
|
11
|
+
export { Epoch } from "./Epoch";
|
|
12
|
+
export { FinalizeResult, FinalizeResultStatus } from "./FinalizeResult";
|
|
13
|
+
export { ResourceAddress } from "./ResourceAddress";
|
|
14
|
+
export { Instruction } from "./Instruction";
|
|
15
|
+
export { Transaction } from "./Transaction";
|
|
16
|
+
export { SubstateDiff, DownSubstates, UpSubstates } from "./SubstateDiff";
|
|
17
|
+
export { SubstateRequirement } from "./SubstateRequirement";
|
|
18
|
+
export { TransactionId } from "./TransactionId";
|
|
19
|
+
export { TransactionResult, TransactionStatus } from "./TransactionResult";
|
|
20
|
+
export { TransactionSignature } from "./TransactionSignature";
|
|
21
|
+
export { UnsignedTransaction } from "./UnsignedTransaction";
|
|
22
|
+
export { VersionedSubstateId } from "./VersionedSubstateId";
|
|
23
|
+
export { ViewableBalanceProof } from "./ViewableBalanceProof";
|
|
24
|
+
export { WorkspaceArg } from "./Workspace";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TariProvider } from "./providers";
|
|
2
|
+
import * as utils from "./utils";
|
|
3
|
+
import { Account, TransactionStatus, TransactionResult, SubmitTransactionResponse, SubmitTransactionRequest, VaultBalances, VaultData, TemplateDefinition, SubstateRequirement, Substate } from "./providers/types";
|
|
4
|
+
import { MetamaskTariProvider } from "./providers/metamask";
|
|
5
|
+
import { MetaMaskInpageProvider } from "@metamask/providers";
|
|
6
|
+
import { WalletDaemonTariProvider, WalletDaemonParameters, TariPermissions } from "./providers/wallet_daemon";
|
|
7
|
+
import { TariUniverseProvider, TariUniverseProviderParameters } from "./providers/tari_universe";
|
|
8
|
+
import * as permissions from "./providers/wallet_daemon";
|
|
9
|
+
import { WalletConnectTariProvider } from "./providers/walletconnect";
|
|
10
|
+
import { TransactionBuilder, TransactionRequest, buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace } from "./builders";
|
|
11
|
+
import { TariswapTemplate, AccountTemplate, PoolTemplate, TestFaucet } from "./templates";
|
|
12
|
+
export * from "./builders/types";
|
|
13
|
+
export { utils, TariProvider, Account, TransactionStatus, TransactionResult, SubmitTransactionResponse, SubmitTransactionRequest, VaultBalances, VaultData, TemplateDefinition, SubstateRequirement, MetamaskTariProvider, WalletDaemonTariProvider, WalletDaemonParameters, TariUniverseProvider, TariUniverseProviderParameters, TariPermissions, MetaMaskInpageProvider, Substate, permissions, WalletConnectTariProvider, TransactionBuilder, AccountTemplate, TariswapTemplate, PoolTemplate, TestFaucet, TransactionRequest, buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace, };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as utils from "./utils";
|
|
2
|
+
import { TransactionStatus, } from "./providers/types";
|
|
3
|
+
import { MetamaskTariProvider } from "./providers/metamask";
|
|
4
|
+
import { MetaMaskInpageProvider } from "@metamask/providers";
|
|
5
|
+
import { WalletDaemonTariProvider, TariPermissions } from "./providers/wallet_daemon";
|
|
6
|
+
import { TariUniverseProvider } from "./providers/tari_universe";
|
|
7
|
+
import * as permissions from "./providers/wallet_daemon";
|
|
8
|
+
import { WalletConnectTariProvider } from "./providers/walletconnect";
|
|
9
|
+
import { TransactionBuilder, TransactionRequest, buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace, } from "./builders";
|
|
10
|
+
import { TariswapTemplate, AccountTemplate, PoolTemplate, TestFaucet } from "./templates";
|
|
11
|
+
export * from "./builders/types";
|
|
12
|
+
export { utils, TransactionStatus, MetamaskTariProvider, WalletDaemonTariProvider, TariUniverseProvider, TariPermissions, MetaMaskInpageProvider, permissions, WalletConnectTariProvider, TransactionBuilder, AccountTemplate, TariswapTemplate, PoolTemplate, TestFaucet, TransactionRequest, buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace, };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SubstateType } from "@tari-project/typescript-bindings";
|
|
2
|
+
import { Account, SubmitTransactionRequest, TransactionResult, SubmitTransactionResponse, VaultBalances, TemplateDefinition, Substate, ListSubstatesResponse } from "./types";
|
|
3
|
+
import { ProviderMethods, ProviderMethodNames, ProviderReturnType } from "./tari_universe/types";
|
|
4
|
+
export type { Account, SubmitTransactionRequest, TransactionResult, SubmitTransactionResponse, VaultBalances, TemplateDefinition, Substate, ListSubstatesResponse, ProviderMethods, ProviderMethodNames, ProviderReturnType, };
|
|
5
|
+
export interface TariProvider {
|
|
6
|
+
providerName: string;
|
|
7
|
+
isConnected(): boolean;
|
|
8
|
+
getAccount(): Promise<Account>;
|
|
9
|
+
getSubstate(substate_address: string): Promise<Substate>;
|
|
10
|
+
submitTransaction(req: SubmitTransactionRequest): Promise<SubmitTransactionResponse>;
|
|
11
|
+
getTransactionResult(transactionId: string): Promise<TransactionResult>;
|
|
12
|
+
getTemplateDefinition(template_address: string): Promise<TemplateDefinition>;
|
|
13
|
+
getPublicKey(branch: string, index: number): Promise<string>;
|
|
14
|
+
getConfidentialVaultBalances(viewKeyId: number, vaultId: string, min: number | null, max: number | null): Promise<VaultBalances>;
|
|
15
|
+
listSubstates(filter_by_template: string | null, filter_by_type: SubstateType | null, limit: number | null, offset: number | null): Promise<ListSubstatesResponse>;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TariProvider } from "../index";
|
|
2
|
+
import { SubmitTransactionRequest, TransactionResult, SubmitTransactionResponse, VaultBalances, TemplateDefinition, Substate, ListSubstatesResponse } from "../types";
|
|
3
|
+
import { MetaMaskInpageProvider } from '@metamask/providers';
|
|
4
|
+
import { Snap } from "./utils";
|
|
5
|
+
import { Account } from "../types";
|
|
6
|
+
import { SubstateType } from "@tari-project/typescript-bindings";
|
|
7
|
+
export declare const MetamaskNotInstalled = "METAMASK_NOT_INSTALLED";
|
|
8
|
+
export declare const MetamaskIsNotFlask = "METAMASK_IS_NOT_FLASK";
|
|
9
|
+
export declare const TariSnapNotInstalled = "TARI_SNAP_NOT_INSTALLED";
|
|
10
|
+
export declare class MetamaskTariProvider implements TariProvider {
|
|
11
|
+
providerName: string;
|
|
12
|
+
snapId: string;
|
|
13
|
+
snapVersion: string | undefined;
|
|
14
|
+
metamask: MetaMaskInpageProvider;
|
|
15
|
+
snap?: Snap;
|
|
16
|
+
metamaskConnected: boolean;
|
|
17
|
+
constructor(snapId: string, metamask: MetaMaskInpageProvider);
|
|
18
|
+
connect(): Promise<void>;
|
|
19
|
+
isConnected(): boolean;
|
|
20
|
+
createFreeTestCoins(account_id: number): Promise<Account>;
|
|
21
|
+
getAccount(): Promise<Account>;
|
|
22
|
+
getSubstate(substate_address: string): Promise<Substate>;
|
|
23
|
+
listSubstates(filter_by_template: string | null, filter_by_type: SubstateType | null, limit: number | null, offset: number | null): Promise<ListSubstatesResponse>;
|
|
24
|
+
submitTransaction(req: SubmitTransactionRequest): Promise<SubmitTransactionResponse>;
|
|
25
|
+
getTransactionResult(transactionId: string): Promise<TransactionResult>;
|
|
26
|
+
getPublicKey(_branch: string, index: number): Promise<string>;
|
|
27
|
+
getConfidentialVaultBalances(viewKeyId: number, vaultId: string, min?: number | null, max?: number | null): Promise<VaultBalances>;
|
|
28
|
+
getTemplateDefinition(template_address: string): Promise<TemplateDefinition>;
|
|
29
|
+
private metamaskRequest;
|
|
30
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { TransactionStatus, } from "../types";
|
|
2
|
+
import { connectSnap, getSnap, isFlask } from "./utils";
|
|
3
|
+
export const MetamaskNotInstalled = 'METAMASK_NOT_INSTALLED';
|
|
4
|
+
export const MetamaskIsNotFlask = 'METAMASK_IS_NOT_FLASK';
|
|
5
|
+
export const TariSnapNotInstalled = 'TARI_SNAP_NOT_INSTALLED';
|
|
6
|
+
export class MetamaskTariProvider {
|
|
7
|
+
providerName = "Metamask";
|
|
8
|
+
snapId;
|
|
9
|
+
snapVersion;
|
|
10
|
+
metamask;
|
|
11
|
+
snap;
|
|
12
|
+
metamaskConnected;
|
|
13
|
+
constructor(snapId, metamask) {
|
|
14
|
+
this.snapId = snapId;
|
|
15
|
+
this.snapVersion = undefined;
|
|
16
|
+
this.metamask = metamask;
|
|
17
|
+
this.metamaskConnected = false;
|
|
18
|
+
}
|
|
19
|
+
async connect() {
|
|
20
|
+
// check that the metamask provider is valid
|
|
21
|
+
if (!this.metamask || !this.metamask.isMetaMask) {
|
|
22
|
+
throw MetamaskNotInstalled;
|
|
23
|
+
}
|
|
24
|
+
// check that flask is installed
|
|
25
|
+
if (!isFlask(this.metamask)) {
|
|
26
|
+
throw MetamaskIsNotFlask;
|
|
27
|
+
}
|
|
28
|
+
// connect to the tari snap
|
|
29
|
+
// this will request MetaMask the installation of the tari snap if it's not already installed
|
|
30
|
+
await connectSnap(this.metamask, { [this.snapId]: { version: this.snapVersion } });
|
|
31
|
+
// store the tari snap reference
|
|
32
|
+
const snap = await getSnap(this.metamask, this.snapId);
|
|
33
|
+
if (!snap) {
|
|
34
|
+
// this should olny happen if the user didn't accept the tari snap in the previous step
|
|
35
|
+
throw TariSnapNotInstalled;
|
|
36
|
+
}
|
|
37
|
+
this.snap = snap;
|
|
38
|
+
this.metamaskConnected = true;
|
|
39
|
+
}
|
|
40
|
+
isConnected() {
|
|
41
|
+
return this.metamaskConnected;
|
|
42
|
+
}
|
|
43
|
+
async createFreeTestCoins(account_id) {
|
|
44
|
+
const res = await this.metamaskRequest('getFreeTestCoins', {
|
|
45
|
+
amount: 1000000,
|
|
46
|
+
account_id,
|
|
47
|
+
fee: 2000
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
account_id,
|
|
51
|
+
address: res.address,
|
|
52
|
+
public_key: res.public_key,
|
|
53
|
+
resources: []
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async getAccount() {
|
|
57
|
+
return await this.metamaskRequest('getAccountData', { account_id: 0 });
|
|
58
|
+
}
|
|
59
|
+
async getSubstate(substate_address) {
|
|
60
|
+
const { substate, address: substate_id, version } = await this.metamaskRequest('getSubstate', { substate_address });
|
|
61
|
+
return { value: substate, address: { substate_id, version } };
|
|
62
|
+
}
|
|
63
|
+
async listSubstates(filter_by_template, filter_by_type, limit, offset) {
|
|
64
|
+
const res = await this.metamaskRequest('listSubstates', {
|
|
65
|
+
filter_by_template,
|
|
66
|
+
filter_by_type,
|
|
67
|
+
limit,
|
|
68
|
+
offset,
|
|
69
|
+
});
|
|
70
|
+
return res;
|
|
71
|
+
}
|
|
72
|
+
async submitTransaction(req) {
|
|
73
|
+
const params = {
|
|
74
|
+
instructions: req.instructions,
|
|
75
|
+
fee_instructions: req.fee_instructions,
|
|
76
|
+
input_refs: req.input_refs,
|
|
77
|
+
required_substates: req.required_substates || [],
|
|
78
|
+
is_dry_run: req.is_dry_run,
|
|
79
|
+
};
|
|
80
|
+
const resp = await this.metamaskRequest('sendTransaction', params);
|
|
81
|
+
if (!resp) {
|
|
82
|
+
throw new Error("Failed to submit transaction to metamask snap: empty response");
|
|
83
|
+
}
|
|
84
|
+
if (resp.error) {
|
|
85
|
+
throw new Error(`Failed to submit transaction to metamask snap: ${resp.error}`);
|
|
86
|
+
}
|
|
87
|
+
return { transaction_id: resp.transaction_id };
|
|
88
|
+
}
|
|
89
|
+
async getTransactionResult(transactionId) {
|
|
90
|
+
// This request returns the response from the indexer get_transaction_result request
|
|
91
|
+
const resp = await this.metamaskRequest('getTransactionResult', { transaction_id: transactionId });
|
|
92
|
+
if (!resp) {
|
|
93
|
+
throw new Error("Failed to get transaction result from metamask snap: empty response");
|
|
94
|
+
}
|
|
95
|
+
if (resp.result === "Pending") {
|
|
96
|
+
return {
|
|
97
|
+
transaction_id: transactionId,
|
|
98
|
+
status: TransactionStatus.Pending,
|
|
99
|
+
result: null
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (!resp?.result?.Finalized) {
|
|
103
|
+
throw new Error("Transaction result was not pending nor finalized");
|
|
104
|
+
}
|
|
105
|
+
const newStatus = convertToStatus(resp.result.Finalized);
|
|
106
|
+
return {
|
|
107
|
+
transaction_id: transactionId,
|
|
108
|
+
status: newStatus,
|
|
109
|
+
result: resp.result.Finalized.execution_result.finalize
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
async getPublicKey(_branch, index) {
|
|
113
|
+
const resp = await this.metamaskRequest('getPublicKey', { index });
|
|
114
|
+
if (!resp) {
|
|
115
|
+
throw new Error("Failed to get public key from metamask snap: empty response");
|
|
116
|
+
}
|
|
117
|
+
return resp.public_key;
|
|
118
|
+
}
|
|
119
|
+
async getConfidentialVaultBalances(viewKeyId, vaultId, min = null, max = null) {
|
|
120
|
+
const res = await this.metamaskRequest('getConfidentialVaultBalances', {
|
|
121
|
+
view_key_id: viewKeyId,
|
|
122
|
+
vault_id: vaultId,
|
|
123
|
+
minimum_expected_value: min,
|
|
124
|
+
maximum_expected_value: max,
|
|
125
|
+
});
|
|
126
|
+
return { balances: res };
|
|
127
|
+
}
|
|
128
|
+
getTemplateDefinition(template_address) {
|
|
129
|
+
return this.metamaskRequest('getTemplateDefinition', { template_address })
|
|
130
|
+
.then(resp => {
|
|
131
|
+
if (!resp) {
|
|
132
|
+
throw new Error("Template not found");
|
|
133
|
+
}
|
|
134
|
+
return resp.definition;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
async metamaskRequest(method, params) {
|
|
138
|
+
console.log("Metamask request:", method, params);
|
|
139
|
+
const resp = await this.metamask.request({
|
|
140
|
+
method: 'wallet_invokeSnap',
|
|
141
|
+
params: {
|
|
142
|
+
snapId: this.snapId,
|
|
143
|
+
request: {
|
|
144
|
+
method,
|
|
145
|
+
params
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
console.log("Metamask response:", resp);
|
|
150
|
+
if (!resp) {
|
|
151
|
+
throw new Error("Metamask request failed: empty response");
|
|
152
|
+
}
|
|
153
|
+
return resp;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function convertToStatus(result) {
|
|
157
|
+
// Ref: https://github.com/tari-project/tari-dan/blob/bb0b31139b770aacd7bb49af865543aa4a9e2de4/dan_layer/wallet/sdk/src/apis/transaction.rs
|
|
158
|
+
if (result.final_decision !== "Commit") {
|
|
159
|
+
return TransactionStatus.Rejected;
|
|
160
|
+
}
|
|
161
|
+
// if (!result?.result?.Finalized) {
|
|
162
|
+
// throw new Error("Transaction result was finalized but no result was returned");
|
|
163
|
+
// }
|
|
164
|
+
//
|
|
165
|
+
// if (result.finalize.AcceptFeeRejectRest) {
|
|
166
|
+
// return TransactionStatus.OnlyFeeAccepted;
|
|
167
|
+
// }
|
|
168
|
+
return TransactionStatus.Accepted;
|
|
169
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { MetaMaskInpageProvider } from '@metamask/providers';
|
|
2
|
+
export type GetSnapsResponse = Record<string, Snap>;
|
|
3
|
+
export type Snap = {
|
|
4
|
+
permissionName: string;
|
|
5
|
+
id: string;
|
|
6
|
+
version: string;
|
|
7
|
+
initialPermissions: Record<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Get the installed snaps in MetaMask.
|
|
11
|
+
*
|
|
12
|
+
* @param provider - The MetaMask inpage provider.
|
|
13
|
+
* @returns The snaps installed in MetaMask.
|
|
14
|
+
*/
|
|
15
|
+
export declare const getSnaps: (provider: MetaMaskInpageProvider) => Promise<GetSnapsResponse>;
|
|
16
|
+
/**
|
|
17
|
+
* Connect a snap to MetaMask.
|
|
18
|
+
*
|
|
19
|
+
* @param snapId - The ID of the snap.
|
|
20
|
+
* @param params - The params to pass with the snap to connect.
|
|
21
|
+
*/
|
|
22
|
+
export declare const connectSnap: (provider: MetaMaskInpageProvider, snaps: Record<string, {
|
|
23
|
+
version?: string;
|
|
24
|
+
}>) => Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Get the snap from MetaMask.
|
|
27
|
+
*
|
|
28
|
+
* @param version - The version of the snap to install (optional).
|
|
29
|
+
* @returns The snap object returned by the extension.
|
|
30
|
+
*/
|
|
31
|
+
export declare const getSnap: (provider: MetaMaskInpageProvider, snapId: string, version?: string) => Promise<Snap | undefined>;
|
|
32
|
+
export declare const isLocalSnap: (snapId: string) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Detect if the wallet injecting the ethereum object is MetaMask Flask.
|
|
35
|
+
*
|
|
36
|
+
* @returns True if the MetaMask version is Flask, false otherwise.
|
|
37
|
+
*/
|
|
38
|
+
export declare const isFlask: (provider: MetaMaskInpageProvider) => Promise<boolean>;
|