@tari-project/tarijs 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/bug_report.md +36 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +27 -0
- package/.github/dependabot.yml +8 -0
- package/.github/workflows/ci.yml +25 -0
- package/.github/workflows/npm_publish.yml +26 -0
- package/.github/workflows/pr_signed_commits_check.yml +19 -0
- package/.github/workflows/pr_title.yml +30 -0
- package/.moon/toolchain.yml +6 -0
- package/.moon/workspace.yml +32 -0
- package/.prettierrc +12 -0
- package/.prototools +9 -0
- package/CODEOWNERS +3 -0
- package/README.md +9 -8
- package/TODO.md +12 -0
- package/package.json +6 -24
- package/packages/builders/moon.yml +55 -0
- package/packages/builders/package.json +30 -0
- package/packages/builders/src/helpers/submitTransaction.ts +97 -0
- package/{dist/builders/helpers/workspace.js → packages/builders/src/helpers/workspace.ts} +10 -7
- package/packages/builders/src/index.ts +9 -0
- package/packages/builders/src/transaction/TransactionBuilder.ts +276 -0
- package/packages/builders/src/transaction/TransactionRequest.ts +93 -0
- package/packages/builders/src/transaction/index.ts +2 -0
- package/packages/builders/tsconfig.json +24 -0
- package/packages/metamask_provider/moon.yml +55 -0
- package/packages/metamask_provider/package.json +30 -0
- package/packages/metamask_provider/src/index.ts +232 -0
- package/packages/metamask_provider/src/utils.ts +86 -0
- package/packages/metamask_provider/tsconfig.json +21 -0
- package/packages/tari_permissions/moon.yml +55 -0
- package/packages/tari_permissions/package.json +26 -0
- package/packages/tari_permissions/src/index.ts +1 -0
- package/packages/tari_permissions/src/tari_permissions.ts +312 -0
- package/packages/tari_permissions/tsconfig.json +15 -0
- package/packages/tari_provider/moon.yml +55 -0
- package/packages/tari_provider/package.json +27 -0
- package/packages/tari_provider/src/TariProvider.ts +35 -0
- package/packages/tari_provider/src/index.ts +3 -0
- package/packages/tari_provider/src/types.ts +82 -0
- package/packages/tari_provider/tsconfig.json +11 -0
- package/packages/tari_universe/moon.yml +55 -0
- package/packages/tari_universe/package.json +31 -0
- package/{dist/providers/tari_universe/index.d.ts → packages/tari_universe/src/index.ts} +1 -1
- package/packages/tari_universe/src/provider.ts +135 -0
- package/{dist/providers/tari_universe/types.d.ts → packages/tari_universe/src/types.ts} +20 -17
- package/packages/tari_universe/src/utils.ts +23 -0
- package/packages/tari_universe/tsconfig.json +24 -0
- package/packages/tarijs/integration-tests/.env +1 -0
- package/packages/tarijs/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +191 -0
- package/packages/tarijs/moon.yml +63 -0
- package/packages/tarijs/package.json +39 -0
- package/packages/tarijs/src/index.ts +69 -0
- package/packages/tarijs/src/network.ts +8 -0
- package/packages/tarijs/src/templates/Account.ts +98 -0
- package/packages/tarijs/src/templates/Pool.ts +42 -0
- package/packages/tarijs/src/templates/Tariswap.ts +101 -0
- package/packages/tarijs/src/templates/TemplateFactory.ts +22 -0
- package/packages/tarijs/src/templates/TestFaucet.ts +72 -0
- package/{dist/utils.js → packages/tarijs/src/utils.ts} +4 -3
- package/packages/tarijs/tsconfig.json +39 -0
- package/packages/tarijs/vitest.config.ts +9 -0
- package/packages/tarijs_types/moon.yml +55 -0
- package/packages/tarijs_types/package.json +27 -0
- package/packages/tarijs_types/src/Amount.ts +113 -0
- package/packages/tarijs_types/src/Arg.ts +3 -0
- package/packages/tarijs_types/src/ComponentAddress.ts +3 -0
- package/packages/tarijs_types/src/ConfidentialClaim.ts +9 -0
- package/packages/tarijs_types/src/ConfidentialOutput.ts +9 -0
- package/packages/tarijs_types/src/ConfidentialOutputStatement.ts +10 -0
- package/packages/tarijs_types/src/ConfidentialStatement.ts +9 -0
- package/packages/tarijs_types/src/ConfidentialWithdrawProof.ts +8 -0
- package/packages/tarijs_types/src/ElgamalVerifiableBalance.ts +4 -0
- package/packages/tarijs_types/src/Epoch.ts +3 -0
- package/packages/tarijs_types/src/FinalizeResult.ts +17 -0
- package/packages/tarijs_types/src/Instruction.ts +29 -0
- package/{dist/builders/types/ResourceAddress.js → packages/tarijs_types/src/ResourceAddress.ts} +2 -1
- package/{dist/builders/types/SubstateDiff.d.ts → packages/tarijs_types/src/SubstateDiff.ts} +4 -2
- package/{dist/builders/types/SubstateRequirement.d.ts → packages/tarijs_types/src/SubstateRequirement.ts} +3 -2
- package/{dist/builders/types/TemplateAddress.js → packages/tarijs_types/src/TemplateAddress.ts} +2 -1
- package/{dist/builders/types/Transaction.d.ts → packages/tarijs_types/src/Transaction.ts} +9 -8
- package/packages/tarijs_types/src/TransactionId.ts +4 -0
- package/packages/tarijs_types/src/TransactionResult.ts +26 -0
- package/packages/tarijs_types/src/TransactionSignature.ts +4 -0
- package/packages/tarijs_types/src/UnsignedTransaction.ts +15 -0
- package/{dist/builders/types/VersionedSubstateId.d.ts → packages/tarijs_types/src/VersionedSubstateId.ts} +3 -2
- package/packages/tarijs_types/src/ViewableBalanceProof.ts +12 -0
- package/{dist/builders/types/Workspace.d.ts → packages/tarijs_types/src/Workspace.ts} +1 -1
- package/{dist/builders/types/index.d.ts → packages/tarijs_types/src/index.ts} +4 -3
- package/packages/tarijs_types/tsconfig.json +15 -0
- package/packages/wallet_daemon/moon.yml +55 -0
- package/packages/wallet_daemon/package.json +29 -0
- package/{dist/providers/wallet_daemon/index.d.ts → packages/wallet_daemon/src/index.ts} +3 -1
- package/packages/wallet_daemon/src/provider.ts +263 -0
- package/packages/wallet_daemon/src/webrtc.ts +229 -0
- package/packages/wallet_daemon/src/webrtc_transport.ts +27 -0
- package/packages/wallet_daemon/tsconfig.json +21 -0
- package/packages/walletconnect/moon.yml +55 -0
- package/packages/walletconnect/package.json +32 -0
- package/packages/walletconnect/src/index.ts +274 -0
- package/packages/walletconnect/tsconfig.json +21 -0
- package/pnpm-workspace.yaml +14 -0
- package/tsconfig.json +42 -0
- package/dist/builders/helpers/index.js +0 -2
- package/dist/builders/helpers/submitTransaction.d.ts +0 -13
- package/dist/builders/helpers/submitTransaction.js +0 -62
- package/dist/builders/helpers/workspace.d.ts +0 -23
- package/dist/builders/index.d.ts +0 -3
- package/dist/builders/index.js +0 -3
- package/dist/builders/transaction/TransactionBuilder.d.ts +0 -44
- package/dist/builders/transaction/TransactionBuilder.js +0 -164
- package/dist/builders/transaction/TransactionRequest.d.ts +0 -27
- package/dist/builders/transaction/TransactionRequest.js +0 -67
- package/dist/builders/transaction/index.d.ts +0 -2
- package/dist/builders/transaction/index.js +0 -2
- package/dist/builders/types/Amount.d.ts +0 -23
- package/dist/builders/types/Amount.js +0 -93
- package/dist/builders/types/Arg.d.ts +0 -1
- package/dist/builders/types/Arg.js +0 -1
- package/dist/builders/types/Builder.d.ts +0 -47
- package/dist/builders/types/Builder.js +0 -1
- package/dist/builders/types/ComponentAddress.d.ts +0 -1
- package/dist/builders/types/ComponentAddress.js +0 -1
- package/dist/builders/types/ConfidentialClaim.d.ts +0 -8
- package/dist/builders/types/ConfidentialClaim.js +0 -1
- package/dist/builders/types/ConfidentialOutput.d.ts +0 -8
- package/dist/builders/types/ConfidentialOutput.js +0 -1
- package/dist/builders/types/ConfidentialOutputStatement.d.ts +0 -9
- package/dist/builders/types/ConfidentialOutputStatement.js +0 -1
- package/dist/builders/types/ConfidentialStatement.d.ts +0 -8
- package/dist/builders/types/ConfidentialStatement.js +0 -1
- package/dist/builders/types/ConfidentialWithdrawProof.d.ts +0 -7
- package/dist/builders/types/ConfidentialWithdrawProof.js +0 -1
- package/dist/builders/types/ElgamalVerifiableBalance.d.ts +0 -4
- package/dist/builders/types/ElgamalVerifiableBalance.js +0 -1
- package/dist/builders/types/Epoch.d.ts +0 -1
- package/dist/builders/types/Epoch.js +0 -1
- package/dist/builders/types/FinalizeResult.d.ts +0 -20
- package/dist/builders/types/FinalizeResult.js +0 -1
- package/dist/builders/types/Instruction.d.ts +0 -56
- package/dist/builders/types/Instruction.js +0 -1
- package/dist/builders/types/ResourceAddress.d.ts +0 -1
- package/dist/builders/types/SubstateDiff.js +0 -1
- package/dist/builders/types/SubstateRequirement.js +0 -1
- package/dist/builders/types/TemplateAddress.d.ts +0 -1
- package/dist/builders/types/Transaction.js +0 -1
- package/dist/builders/types/TransactionId.d.ts +0 -1
- package/dist/builders/types/TransactionId.js +0 -1
- package/dist/builders/types/TransactionResult.d.ts +0 -22
- package/dist/builders/types/TransactionResult.js +0 -10
- package/dist/builders/types/TransactionSignature.d.ts +0 -4
- package/dist/builders/types/TransactionSignature.js +0 -1
- package/dist/builders/types/UnsignedTransaction.d.ts +0 -12
- package/dist/builders/types/UnsignedTransaction.js +0 -1
- package/dist/builders/types/VersionedSubstateId.js +0 -1
- package/dist/builders/types/ViewableBalanceProof.d.ts +0 -10
- package/dist/builders/types/ViewableBalanceProof.js +0 -2
- package/dist/builders/types/Workspace.js +0 -1
- package/dist/builders/types/index.js +0 -2
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -12
- package/dist/providers/index.d.ts +0 -16
- package/dist/providers/index.js +0 -1
- package/dist/providers/metamask/index.d.ts +0 -30
- package/dist/providers/metamask/index.js +0 -168
- package/dist/providers/metamask/utils.d.ts +0 -38
- package/dist/providers/metamask/utils.js +0 -55
- package/dist/providers/tari_universe/index.js +0 -3
- package/dist/providers/tari_universe/provider.d.ts +0 -23
- package/dist/providers/tari_universe/provider.js +0 -89
- package/dist/providers/tari_universe/types.js +0 -1
- package/dist/providers/tari_universe/utils.d.ts +0 -2
- package/dist/providers/tari_universe/utils.js +0 -16
- package/dist/providers/types.d.ts +0 -69
- package/dist/providers/types.js +0 -10
- package/dist/providers/wallet_daemon/index.js +0 -3
- package/dist/providers/wallet_daemon/provider.d.ts +0 -43
- package/dist/providers/wallet_daemon/provider.js +0 -198
- package/dist/providers/wallet_daemon/tari_permissions.d.ts +0 -216
- package/dist/providers/wallet_daemon/tari_permissions.js +0 -282
- package/dist/providers/wallet_daemon/webrtc.d.ts +0 -20
- package/dist/providers/wallet_daemon/webrtc.js +0 -201
- package/dist/providers/wallet_daemon/webrtc_transport.d.ts +0 -10
- package/dist/providers/wallet_daemon/webrtc_transport.js +0 -18
- package/dist/providers/walletconnect/index.d.ts +0 -23
- package/dist/providers/walletconnect/index.js +0 -221
- package/dist/templates/Account.d.ts +0 -65
- package/dist/templates/Account.js +0 -31
- package/dist/templates/Pool.d.ts +0 -30
- package/dist/templates/Pool.js +0 -20
- package/dist/templates/Tariswap.d.ts +0 -65
- package/dist/templates/Tariswap.js +0 -36
- package/dist/templates/TemplateFactory.d.ts +0 -9
- package/dist/templates/TemplateFactory.js +0 -18
- package/dist/templates/TestFaucet.d.ts +0 -49
- package/dist/templates/TestFaucet.js +0 -31
- package/dist/templates/index.js +0 -5
- package/dist/utils.d.ts +0 -2
- /package/{dist/builders/helpers/index.d.ts → packages/builders/src/helpers/index.ts} +0 -0
- /package/{dist/templates/index.d.ts → packages/tarijs/src/templates/index.ts} +0 -0
|
@@ -0,0 +1,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
|
+
}
|