@tari-project/tarijs 0.4.0 → 0.4.2
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 +26 -0
- package/.github/workflows/documentation-deploy.yml +44 -0
- package/.github/workflows/documentation-test-deploy.yml +20 -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 +33 -0
- package/.prettierrc +12 -0
- package/.prototools +9 -0
- package/CODEOWNERS +3 -0
- package/README.md +66 -0
- package/TODO.md +12 -0
- package/docusaurus/tari-docs/README.md +41 -0
- package/docusaurus/tari-docs/docs/index.md +16 -0
- package/docusaurus/tari-docs/docs/installation.md +27 -0
- package/docusaurus/tari-docs/docs/providers/_category_.json +8 -0
- package/docusaurus/tari-docs/docs/providers/tari-universe.md +27 -0
- package/docusaurus/tari-docs/docs/providers/wallet-connect.md +52 -0
- package/docusaurus/tari-docs/docs/providers/wallet-daemon.md +37 -0
- package/docusaurus/tari-docs/docs/wallet/_category_.json +8 -0
- package/docusaurus/tari-docs/docs/wallet/default-account.md +51 -0
- package/docusaurus/tari-docs/docs/wallet/get-substate.md +110 -0
- package/docusaurus/tari-docs/docs/wallet/list-substates.md +69 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/_category_.json +8 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/build-execute-request.md +38 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/index.md +14 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/_category_.json +8 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/call-function.md +17 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/call-method.md +17 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/fee.md +28 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/index.md +426 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/inputs.md +24 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/instruction.md +108 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/min-max-epoch.md +19 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/raw-instructions.md +16 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/save-var.md +63 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/transaction-internals.md +20 -0
- package/docusaurus/tari-docs/docs/wallet/template-definition.md +101 -0
- package/docusaurus/tari-docs/docusaurus.config.ts +108 -0
- package/docusaurus/tari-docs/moon.yml +41 -0
- package/docusaurus/tari-docs/package.json +49 -0
- package/docusaurus/tari-docs/sidebars.ts +7 -0
- package/docusaurus/tari-docs/src/components/HomepageFeatures/index.tsx +69 -0
- package/docusaurus/tari-docs/src/components/HomepageFeatures/styles.module.css +11 -0
- package/docusaurus/tari-docs/src/css/custom.css +30 -0
- package/docusaurus/tari-docs/src/pages/index.module.css +23 -0
- package/docusaurus/tari-docs/src/pages/index.tsx +44 -0
- package/docusaurus/tari-docs/static/.nojekyll +0 -0
- package/docusaurus/tari-docs/static/img/favicon.png +0 -0
- package/docusaurus/tari-docs/static/img/meta-image.png +0 -0
- package/docusaurus/tari-docs/static/img/tari/wallet-connect-1.png +0 -0
- package/docusaurus/tari-docs/static/img/tari/wallet-connect-2.png +0 -0
- package/docusaurus/tari-docs/static/img/tari/wallet-connect-3.png +0 -0
- package/docusaurus/tari-docs/static/img/tari-logo.svg +30 -0
- package/docusaurus/tari-docs/tsconfig.json +8 -0
- package/package.json +4 -28
- package/packages/builders/moon.yml +55 -0
- package/packages/builders/package.json +30 -0
- package/packages/builders/src/helpers/index.ts +2 -0
- package/packages/builders/src/helpers/submitTransaction.ts +97 -0
- package/packages/builders/src/helpers/workspace.ts +32 -0
- 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 +34 -0
- package/packages/tari_provider/src/index.ts +3 -0
- package/packages/tari_provider/src/types.ts +84 -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/packages/tari_universe/src/index.ts +3 -0
- package/packages/tari_universe/src/provider.ts +120 -0
- package/packages/tari_universe/src/types.ts +33 -0
- 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 +71 -0
- package/packages/tarijs/package.json +40 -0
- package/packages/tarijs/src/cbor.spec.ts +259 -0
- package/packages/tarijs/src/cbor.ts +114 -0
- package/packages/tarijs/src/index.ts +72 -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/packages/tarijs_types/src/ResourceAddress.ts +3 -0
- package/packages/tarijs_types/src/SubstateDiff.ts +9 -0
- package/packages/tarijs_types/src/SubstateRequirement.ts +6 -0
- package/packages/tarijs_types/src/TemplateAddress.ts +3 -0
- package/packages/tarijs_types/src/Transaction.ts +16 -0
- 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/packages/tarijs_types/src/VersionedSubstateId.ts +6 -0
- package/packages/tarijs_types/src/ViewableBalanceProof.ts +12 -0
- package/packages/tarijs_types/src/Workspace.ts +3 -0
- package/packages/tarijs_types/src/index.ts +25 -0
- 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/packages/wallet_daemon/src/index.ts +5 -0
- 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 +15 -0
- package/tsconfig.json +45 -0
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -13
- package/dist/network.d.ts +0 -8
- package/dist/network.js +0 -9
- package/dist/templates/Account.d.ts +0 -65
- package/dist/templates/Account.js +0 -31
- package/dist/templates/Pool.d.ts +0 -29
- package/dist/templates/Pool.js +0 -20
- package/dist/templates/Tariswap.d.ts +0 -64
- 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/templates/index.d.ts → packages/tarijs/src/templates/index.ts} +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { TariUniverseProvider } from "@tari-project/tari-universe-provider";
|
|
2
|
+
import { TariProvider, SubmitTransactionRequest, SubstateRequirement } from "@tari-project/tari-provider";
|
|
3
|
+
import {
|
|
4
|
+
Transaction,
|
|
5
|
+
TransactionResult,
|
|
6
|
+
TransactionStatus,
|
|
7
|
+
DownSubstates,
|
|
8
|
+
UpSubstates,
|
|
9
|
+
FinalizeResultStatus,
|
|
10
|
+
TxResultAccept,
|
|
11
|
+
SubmitTxResult
|
|
12
|
+
} from "@tari-project/tarijs-types";
|
|
13
|
+
|
|
14
|
+
export function buildTransactionRequest(
|
|
15
|
+
transaction: Transaction,
|
|
16
|
+
accountId: number,
|
|
17
|
+
requiredSubstates: SubstateRequirement[],
|
|
18
|
+
inputRefs = [],
|
|
19
|
+
isDryRun = false,
|
|
20
|
+
network = 0,
|
|
21
|
+
isSealSignerAuthorized = true,
|
|
22
|
+
detectInputsUseUnversioned = true,
|
|
23
|
+
): SubmitTransactionRequest {
|
|
24
|
+
return {
|
|
25
|
+
//TODO refactor SubTxReq type to not use 'object[]' and types match
|
|
26
|
+
// https://github.com/tari-project/tari.js/issues/25
|
|
27
|
+
network,
|
|
28
|
+
account_id: accountId,
|
|
29
|
+
instructions: transaction.instructions as object[],
|
|
30
|
+
fee_instructions: transaction.feeInstructions as object[],
|
|
31
|
+
inputs: transaction.inputs,
|
|
32
|
+
input_refs: inputRefs as object[],
|
|
33
|
+
required_substates: requiredSubstates,
|
|
34
|
+
is_dry_run: isDryRun,
|
|
35
|
+
min_epoch: transaction.minEpoch ?? null,
|
|
36
|
+
max_epoch: transaction.maxEpoch ?? null,
|
|
37
|
+
is_seal_signer_authorized: isSealSignerAuthorized,
|
|
38
|
+
detect_inputs_use_unversioned: detectInputsUseUnversioned,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function submitAndWaitForTransaction(
|
|
43
|
+
provider: TariProvider,
|
|
44
|
+
req: SubmitTransactionRequest,
|
|
45
|
+
): Promise<SubmitTxResult> {
|
|
46
|
+
try {
|
|
47
|
+
const response = await provider.submitTransaction(req);
|
|
48
|
+
const result = await waitForTransactionResult(provider, response.transaction_id);
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
response,
|
|
52
|
+
result,
|
|
53
|
+
};
|
|
54
|
+
} catch (e) {
|
|
55
|
+
throw new Error(`Transaction failed: ${e}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function waitForTransactionResult(
|
|
60
|
+
provider: TariProvider | TariUniverseProvider,
|
|
61
|
+
transactionId: string,
|
|
62
|
+
): Promise<TransactionResult> {
|
|
63
|
+
// eslint-disable-next-line no-constant-condition
|
|
64
|
+
while (true) {
|
|
65
|
+
const resp = await provider.getTransactionResult(transactionId);
|
|
66
|
+
const FINALIZED_STATUSES = [
|
|
67
|
+
TransactionStatus.Accepted,
|
|
68
|
+
TransactionStatus.Rejected,
|
|
69
|
+
TransactionStatus.InvalidTransaction,
|
|
70
|
+
TransactionStatus.OnlyFeeAccepted,
|
|
71
|
+
TransactionStatus.DryRun,
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
if (resp.status == TransactionStatus.Rejected) {
|
|
75
|
+
throw new Error(`Transaction rejected: ${JSON.stringify(resp.result)}`);
|
|
76
|
+
}
|
|
77
|
+
if (FINALIZED_STATUSES.includes(resp.status)) {
|
|
78
|
+
return resp as any as TransactionResult; //TODO fix: type mismatch (https://github.com/tari-project/tari.js/issues/29)
|
|
79
|
+
}
|
|
80
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function getAcceptResultSubstates(
|
|
85
|
+
txResult: TransactionResult,
|
|
86
|
+
): { upSubstates: UpSubstates; downSubstates: DownSubstates } | undefined {
|
|
87
|
+
const result = txResult.result?.result;
|
|
88
|
+
|
|
89
|
+
if (result && isAccept(result)) {
|
|
90
|
+
return { upSubstates: result.Accept.up_substates, downSubstates: result.Accept.down_substates };
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function isAccept(result: FinalizeResultStatus): result is TxResultAccept {
|
|
96
|
+
return "Accept" in result;
|
|
97
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WorkspaceArg } from "@tari-project/tarijs-types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param key workspace name
|
|
6
|
+
* @returns encoded Uint8Array value
|
|
7
|
+
* @example
|
|
8
|
+
* key: "0" -> [ 48 ]
|
|
9
|
+
* key: "0.0" -> [ 48, 46, 48 ]
|
|
10
|
+
* key: "0.1" -> [ 48, 46, 49 ]
|
|
11
|
+
*
|
|
12
|
+
* key: "bucket" -> [ 98, 117, 99, 107, 101, 116 ]
|
|
13
|
+
* key: "bucket.0" -> [ 98, 117, 99, 107, 101, 116, 46, 48 ]
|
|
14
|
+
* key: "bucket.1" -> [ 98, 117, 99, 107, 101, 116, 46, 49 ]
|
|
15
|
+
*/
|
|
16
|
+
export function toWorkspace(key: string): number[] {
|
|
17
|
+
const encoder = new TextEncoder();
|
|
18
|
+
return Array.from(encoder.encode(key));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param key workspace name
|
|
24
|
+
* @returns formatted Workspace data
|
|
25
|
+
* @example
|
|
26
|
+
* key: "bucket" -> { Workspace: [ 98, 117, 99, 107, 101, 116 ] }
|
|
27
|
+
*/
|
|
28
|
+
export function fromWorkspace(key: string): WorkspaceArg {
|
|
29
|
+
const encoder = new TextEncoder();
|
|
30
|
+
const encodedKey = encoder.encode(key);
|
|
31
|
+
return { Workspace: Array.from(encodedKey) };
|
|
32
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "@tari-project/tarijs-types";
|
|
2
|
+
export { TransactionBuilder, TransactionRequest, TariMethodDefinition, TariFunctionDefinition } from "./transaction";
|
|
3
|
+
export {
|
|
4
|
+
buildTransactionRequest,
|
|
5
|
+
submitAndWaitForTransaction,
|
|
6
|
+
waitForTransactionResult,
|
|
7
|
+
fromWorkspace,
|
|
8
|
+
toWorkspace,
|
|
9
|
+
} from "./helpers";
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
// Copyright 2024 The Tari Project
|
|
2
|
+
// SPDX-License-Identifier: BSD-3-Clause
|
|
3
|
+
import { toWorkspace } from "../helpers";
|
|
4
|
+
|
|
5
|
+
import { TransactionRequest } from "./TransactionRequest";
|
|
6
|
+
import {
|
|
7
|
+
ComponentAddress,
|
|
8
|
+
ConfidentialClaim,
|
|
9
|
+
ConfidentialWithdrawProof,
|
|
10
|
+
Instruction,
|
|
11
|
+
ResourceAddress,
|
|
12
|
+
SubstateRequirement,
|
|
13
|
+
Transaction,
|
|
14
|
+
TransactionSignature,
|
|
15
|
+
UnsignedTransaction,
|
|
16
|
+
TemplateAddress,
|
|
17
|
+
Arg,
|
|
18
|
+
} from "@tari-project/tarijs-types";
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export interface TransactionConstructor {
|
|
22
|
+
new(unsignedTransaction: UnsignedTransaction, signatures: TransactionSignature[]): Transaction;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface TariFunctionDefinition {
|
|
26
|
+
functionName: string;
|
|
27
|
+
args?: Arg[];
|
|
28
|
+
templateAddress: TemplateAddress;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface TariMethodDefinition {
|
|
32
|
+
methodName: string;
|
|
33
|
+
args?: Arg[];
|
|
34
|
+
componentAddress: ComponentAddress;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface TariCreateAccountDefinition {
|
|
38
|
+
methodName: string;
|
|
39
|
+
args?: {
|
|
40
|
+
ownerPublicKey: string;
|
|
41
|
+
workspaceBucket?: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface Builder {
|
|
46
|
+
callFunction<T extends TariFunctionDefinition>(func: T, args: Exclude<T["args"], undefined>): this;
|
|
47
|
+
|
|
48
|
+
callMethod<T extends TariMethodDefinition>(method: T, args: Exclude<T["args"], undefined>): this;
|
|
49
|
+
|
|
50
|
+
createAccount(ownerPublicKey: string, workspaceBucket?: string): this;
|
|
51
|
+
|
|
52
|
+
createProof(account: ComponentAddress, resourceAddress: ResourceAddress): this;
|
|
53
|
+
|
|
54
|
+
saveVar(key: string): this;
|
|
55
|
+
|
|
56
|
+
dropAllProofsInWorkspace(): this;
|
|
57
|
+
|
|
58
|
+
claimBurn(claim: ConfidentialClaim): this;
|
|
59
|
+
|
|
60
|
+
addInput(inputObject: SubstateRequirement): this;
|
|
61
|
+
|
|
62
|
+
addInstruction(instruction: Instruction): this;
|
|
63
|
+
|
|
64
|
+
addFeeInstruction(instruction: Instruction): this;
|
|
65
|
+
|
|
66
|
+
withMinEpoch(minEpoch: number): this;
|
|
67
|
+
|
|
68
|
+
withMaxEpoch(maxEpoch: number): this;
|
|
69
|
+
|
|
70
|
+
withInputs(inputs: SubstateRequirement[]): this;
|
|
71
|
+
|
|
72
|
+
withInstructions(instructions: Instruction[]): this;
|
|
73
|
+
|
|
74
|
+
withFeeInstructions(instructions: Instruction[]): this;
|
|
75
|
+
|
|
76
|
+
withFeeInstructionsBuilder(builder: (builder: TransactionBuilder) => this): this;
|
|
77
|
+
|
|
78
|
+
withUnsignedTransaction(unsignedTransaction: UnsignedTransaction): this;
|
|
79
|
+
|
|
80
|
+
feeTransactionPayFromComponent(componentAddress: ComponentAddress, maxFee: string): this;
|
|
81
|
+
|
|
82
|
+
feeTransactionPayFromComponentConfidential(
|
|
83
|
+
componentAddress: ComponentAddress,
|
|
84
|
+
proof: ConfidentialWithdrawProof,
|
|
85
|
+
): this;
|
|
86
|
+
|
|
87
|
+
buildUnsignedTransaction(): UnsignedTransaction;
|
|
88
|
+
|
|
89
|
+
build(): Transaction;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export class TransactionBuilder implements Builder {
|
|
93
|
+
private unsignedTransaction: UnsignedTransaction;
|
|
94
|
+
private signatures: TransactionSignature[];
|
|
95
|
+
|
|
96
|
+
constructor() {
|
|
97
|
+
this.unsignedTransaction = {
|
|
98
|
+
feeInstructions: [],
|
|
99
|
+
instructions: [],
|
|
100
|
+
inputs: [],
|
|
101
|
+
filledInputs: [],
|
|
102
|
+
minEpoch: undefined,
|
|
103
|
+
maxEpoch: undefined,
|
|
104
|
+
};
|
|
105
|
+
this.signatures = [];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public callFunction<T extends TariFunctionDefinition>(func: T, args: Exclude<T["args"], undefined>): this {
|
|
109
|
+
return this.addInstruction({
|
|
110
|
+
CallFunction: {
|
|
111
|
+
template_address: func.templateAddress,
|
|
112
|
+
function: func.functionName,
|
|
113
|
+
args,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public callMethod<T extends TariMethodDefinition>(method: T, args: Exclude<T["args"], undefined>): this {
|
|
119
|
+
return this.addInstruction({
|
|
120
|
+
CallMethod: {
|
|
121
|
+
component_address: method.componentAddress,
|
|
122
|
+
method: method.methodName,
|
|
123
|
+
args,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public createAccount(ownerPublicKey: string, workspaceBucket?: string): this {
|
|
129
|
+
return this.addInstruction({
|
|
130
|
+
CreateAccount: {
|
|
131
|
+
owner_public_key: ownerPublicKey,
|
|
132
|
+
workspace_bucket: workspaceBucket ?? null,
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public createProof(account: ComponentAddress, resourceAddress: ResourceAddress): this {
|
|
138
|
+
return this.addInstruction({
|
|
139
|
+
CallMethod: {
|
|
140
|
+
component_address: account,
|
|
141
|
+
method: "create_proof_for_resource",
|
|
142
|
+
args: [resourceAddress],
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public claimBurn(claim: ConfidentialClaim): this {
|
|
148
|
+
return this.addInstruction({
|
|
149
|
+
ClaimBurn: {
|
|
150
|
+
claim,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The `SaveVar` method replaces
|
|
157
|
+
* `PutLastInstructionOutputOnWorkspace: { key: Array<number> }`
|
|
158
|
+
* to make saving variables easier.
|
|
159
|
+
*/
|
|
160
|
+
public saveVar(key: string): this {
|
|
161
|
+
return this.addInstruction({
|
|
162
|
+
PutLastInstructionOutputOnWorkspace: {
|
|
163
|
+
key: toWorkspace(key),
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Adds a fee instruction that calls the `take_fee` method on a component.
|
|
170
|
+
* This method must exist and return a Bucket with containing revealed confidential XTR resource.
|
|
171
|
+
* This allows the fee to originate from sources other than the transaction sender's account.
|
|
172
|
+
* The fee instruction will lock up the `max_fee` amount for the duration of the transaction.
|
|
173
|
+
*/
|
|
174
|
+
public feeTransactionPayFromComponent(componentAddress: ComponentAddress, maxFee: string): this {
|
|
175
|
+
return this.addFeeInstruction({
|
|
176
|
+
CallMethod: {
|
|
177
|
+
component_address: componentAddress,
|
|
178
|
+
method: "pay_fee",
|
|
179
|
+
args: [maxFee],
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Adds a fee instruction that calls the `take_fee_confidential` method on a component.
|
|
186
|
+
* This method must exist and return a Bucket with containing revealed confidential XTR resource.
|
|
187
|
+
* This allows the fee to originate from sources other than the transaction sender's account.
|
|
188
|
+
*/
|
|
189
|
+
public feeTransactionPayFromComponentConfidential(
|
|
190
|
+
componentAddress: ComponentAddress,
|
|
191
|
+
proof: ConfidentialWithdrawProof,
|
|
192
|
+
): this {
|
|
193
|
+
return this.addFeeInstruction({
|
|
194
|
+
CallMethod: {
|
|
195
|
+
component_address: componentAddress,
|
|
196
|
+
method: "pay_fee_confidential",
|
|
197
|
+
args: [proof],
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
public dropAllProofsInWorkspace(): this {
|
|
203
|
+
return this.addInstruction("DropAllProofsInWorkspace");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
public withUnsignedTransaction(unsignedTransaction: UnsignedTransaction): this {
|
|
207
|
+
this.unsignedTransaction = unsignedTransaction;
|
|
208
|
+
this.signatures = [];
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
public withFeeInstructions(instructions: Instruction[]): this {
|
|
213
|
+
this.unsignedTransaction.feeInstructions = instructions;
|
|
214
|
+
this.signatures = [];
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
public withFeeInstructionsBuilder(builder: (builder: TransactionBuilder) => TransactionBuilder): this {
|
|
219
|
+
const newBuilder = builder(new TransactionBuilder());
|
|
220
|
+
this.unsignedTransaction.feeInstructions = newBuilder.unsignedTransaction.instructions;
|
|
221
|
+
this.signatures = [];
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
public addInstruction(instruction: Instruction): this {
|
|
226
|
+
this.unsignedTransaction.instructions.push(instruction);
|
|
227
|
+
this.signatures = [];
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
public addFeeInstruction(instruction: Instruction): this {
|
|
232
|
+
this.unsignedTransaction.feeInstructions.push(instruction);
|
|
233
|
+
this.signatures = [];
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
public withInstructions(instructions: Instruction[]): this {
|
|
238
|
+
this.unsignedTransaction.instructions.push(...instructions);
|
|
239
|
+
this.signatures = [];
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
public addInput(inputObject: SubstateRequirement): this {
|
|
244
|
+
this.unsignedTransaction.inputs.push(inputObject);
|
|
245
|
+
this.signatures = [];
|
|
246
|
+
return this;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
public withInputs(inputs: SubstateRequirement[]): this {
|
|
250
|
+
this.unsignedTransaction.inputs.push(...inputs);
|
|
251
|
+
this.signatures = [];
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
public withMinEpoch(minEpoch: number): this {
|
|
256
|
+
this.unsignedTransaction.minEpoch = minEpoch;
|
|
257
|
+
// Reset the signatures as they are no longer valid
|
|
258
|
+
this.signatures = [];
|
|
259
|
+
return this;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
public withMaxEpoch(maxEpoch: number): this {
|
|
263
|
+
this.unsignedTransaction.maxEpoch = maxEpoch;
|
|
264
|
+
// Reset the signatures as they are no longer valid
|
|
265
|
+
this.signatures = [];
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
public buildUnsignedTransaction(): UnsignedTransaction {
|
|
270
|
+
return this.unsignedTransaction;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
public build(): Transaction {
|
|
274
|
+
return new TransactionRequest(this.unsignedTransaction, this.signatures);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Epoch,
|
|
3
|
+
Instruction,
|
|
4
|
+
SubstateRequirement,
|
|
5
|
+
Transaction,
|
|
6
|
+
TransactionId,
|
|
7
|
+
TransactionSignature,
|
|
8
|
+
UnsignedTransaction,
|
|
9
|
+
VersionedSubstateId,
|
|
10
|
+
} from "@tari-project/tarijs-types";
|
|
11
|
+
|
|
12
|
+
///TODO this implementation is not fully done, see:
|
|
13
|
+
/// https://github.com/tari-project/tari-dan/blob/development/dan_layer/transaction/src/transaction.rs
|
|
14
|
+
export class TransactionRequest implements Transaction {
|
|
15
|
+
id: TransactionId;
|
|
16
|
+
feeInstructions: Array<Instruction>;
|
|
17
|
+
instructions: Array<Instruction>;
|
|
18
|
+
inputs: Array<SubstateRequirement>;
|
|
19
|
+
signatures: Array<TransactionSignature>;
|
|
20
|
+
unsignedTransaction: UnsignedTransaction;
|
|
21
|
+
minEpoch?: Epoch;
|
|
22
|
+
maxEpoch?: Epoch;
|
|
23
|
+
filledInputs: VersionedSubstateId[];
|
|
24
|
+
|
|
25
|
+
constructor(unsignedTransaction: UnsignedTransaction, signatures: TransactionSignature[]) {
|
|
26
|
+
this.id = this.calculateHash();
|
|
27
|
+
this.feeInstructions = unsignedTransaction.feeInstructions;
|
|
28
|
+
this.instructions = unsignedTransaction.instructions;
|
|
29
|
+
this.inputs = unsignedTransaction.inputs;
|
|
30
|
+
this.signatures = signatures;
|
|
31
|
+
this.minEpoch = unsignedTransaction.minEpoch;
|
|
32
|
+
this.maxEpoch = unsignedTransaction.maxEpoch;
|
|
33
|
+
// Inputs filled by some authority. These are not part of the transaction hash nor the signature
|
|
34
|
+
this.filledInputs = [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private calculateHash(): TransactionId {
|
|
38
|
+
return "";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
withFilledInputs(filled_inputs: Array<VersionedSubstateId>): this {
|
|
42
|
+
return { ...this, filled_inputs };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getId(): TransactionId {
|
|
46
|
+
return this.id;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
checkId(): boolean {
|
|
50
|
+
const id = this.calculateHash();
|
|
51
|
+
return id === this.id;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getUnsignedTransaction(): UnsignedTransaction {
|
|
55
|
+
return this.unsignedTransaction;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getFeeInstructions(): Instruction[] {
|
|
59
|
+
return this.feeInstructions;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getInstructions(): Instruction[] {
|
|
63
|
+
return this.instructions;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getSignatures(): TransactionSignature[] {
|
|
67
|
+
return this.signatures;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getHash(): string {
|
|
71
|
+
return this.id;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getInputs(): SubstateRequirement[] {
|
|
75
|
+
return this.inputs;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getFilledInputs(): VersionedSubstateId[] {
|
|
79
|
+
return this.filledInputs;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
getFilledInputsMut(): VersionedSubstateId[] {
|
|
83
|
+
return this.filledInputs;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
getMinEpoch(): Epoch | undefined {
|
|
87
|
+
return this.minEpoch;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
getMaxEpoch(): Epoch | undefined {
|
|
91
|
+
return this.maxEpoch;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -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_provider"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "../tari_universe"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"path": "../tarijs_types"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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)"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tari-project/metamask-provider",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc -b"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@metamask/providers": "catalog:",
|
|
17
|
+
"@tari-project/tari-provider": "workspace:^",
|
|
18
|
+
"@tari-project/tarijs-types": "workspace:^",
|
|
19
|
+
"@tari-project/typescript-bindings": "catalog:"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "catalog:",
|
|
23
|
+
"typescript": "catalog:"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"/dist"
|
|
27
|
+
],
|
|
28
|
+
"main": "dist/index.js",
|
|
29
|
+
"types": "dist/index.d.ts"
|
|
30
|
+
}
|