@tari-project/tarijs 0.3.0 → 0.4.0
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/index.d.ts +11 -10
- package/dist/index.js +10 -9
- package/dist/network.d.ts +8 -0
- package/dist/network.js +9 -0
- package/dist/templates/Account.d.ts +2 -2
- package/dist/templates/Pool.d.ts +1 -2
- package/dist/templates/Tariswap.d.ts +1 -2
- package/dist/templates/TemplateFactory.d.ts +1 -1
- package/dist/templates/TestFaucet.d.ts +1 -1
- package/package.json +20 -12
- package/README.md +0 -46
- package/dist/builders/helpers/index.d.ts +0 -2
- package/dist/builders/helpers/index.js +0 -2
- package/dist/builders/helpers/submitTransaction.d.ts +0 -13
- package/dist/builders/helpers/submitTransaction.js +0 -59
- package/dist/builders/helpers/workspace.d.ts +0 -23
- package/dist/builders/helpers/workspace.js +0 -29
- 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/ResourceAddress.js +0 -2
- package/dist/builders/types/SubstateDiff.d.ts +0 -7
- package/dist/builders/types/SubstateDiff.js +0 -1
- package/dist/builders/types/SubstateRequirement.d.ts +0 -5
- package/dist/builders/types/SubstateRequirement.js +0 -1
- package/dist/builders/types/TemplateAddress.d.ts +0 -1
- package/dist/builders/types/TemplateAddress.js +0 -2
- package/dist/builders/types/Transaction.d.ts +0 -15
- 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.d.ts +0 -5
- 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.d.ts +0 -3
- package/dist/builders/types/Workspace.js +0 -1
- package/dist/builders/types/index.d.ts +0 -24
- package/dist/builders/types/index.js +0 -2
- 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.d.ts +0 -3
- 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.d.ts +0 -30
- 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 -66
- package/dist/providers/types.js +0 -10
- package/dist/providers/wallet_daemon/index.d.ts +0 -3
- package/dist/providers/wallet_daemon/index.js +0 -3
- package/dist/providers/wallet_daemon/provider.d.ts +0 -35
- package/dist/providers/wallet_daemon/provider.js +0 -173
- 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 -217
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
class SignaligServer {
|
|
2
|
-
_token;
|
|
3
|
-
_server_url;
|
|
4
|
-
constructor(server_url) {
|
|
5
|
-
console.log(server_url);
|
|
6
|
-
if (server_url !== undefined) {
|
|
7
|
-
this._server_url = server_url;
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
this._server_url = "http://localhost:9100";
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
async initToken(permissions) {
|
|
14
|
-
this._token = await this.authLogin(permissions);
|
|
15
|
-
}
|
|
16
|
-
get token() {
|
|
17
|
-
return this._token;
|
|
18
|
-
}
|
|
19
|
-
async jsonRpc(method, token, params) {
|
|
20
|
-
console.log('jsonRpc', method, token, params);
|
|
21
|
-
let id = 0;
|
|
22
|
-
id += 1;
|
|
23
|
-
let address = this._server_url;
|
|
24
|
-
let headers = { 'Content-Type': 'application/json' };
|
|
25
|
-
if (token) {
|
|
26
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
27
|
-
}
|
|
28
|
-
let response = await fetch(address, {
|
|
29
|
-
method: 'POST',
|
|
30
|
-
body: JSON.stringify({
|
|
31
|
-
method: method,
|
|
32
|
-
jsonrpc: '2.0',
|
|
33
|
-
id: id,
|
|
34
|
-
params: params || {},
|
|
35
|
-
}),
|
|
36
|
-
headers: headers
|
|
37
|
-
});
|
|
38
|
-
let json = await response.json();
|
|
39
|
-
if (json.error) {
|
|
40
|
-
throw json.error;
|
|
41
|
-
}
|
|
42
|
-
return json.result;
|
|
43
|
-
}
|
|
44
|
-
async authLogin(permissions) {
|
|
45
|
-
return await this.jsonRpc("auth.login", undefined, permissions);
|
|
46
|
-
}
|
|
47
|
-
async storeIceCandidate(ice_candidate) {
|
|
48
|
-
return await this.jsonRpc("add.offer_ice_candidate", this._token, ice_candidate);
|
|
49
|
-
}
|
|
50
|
-
async storeOffer(offer) {
|
|
51
|
-
return await this.jsonRpc("add.offer", this._token, offer.sdp);
|
|
52
|
-
}
|
|
53
|
-
async getAnswer() {
|
|
54
|
-
return await this.jsonRpc("get.answer", this._token);
|
|
55
|
-
}
|
|
56
|
-
async getIceCandidates() {
|
|
57
|
-
return await this.jsonRpc("get.answer_ice_candidates", this._token);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
export class TariConnection {
|
|
61
|
-
_peerConnection;
|
|
62
|
-
_dataChannel;
|
|
63
|
-
_signalingServer;
|
|
64
|
-
_callbacks;
|
|
65
|
-
_offer;
|
|
66
|
-
_walletToken;
|
|
67
|
-
// This is public so that user can directly set the onopen callback that will be called once the data channel is open.
|
|
68
|
-
onopen;
|
|
69
|
-
onConnection;
|
|
70
|
-
constructor(signalig_server_url, config) {
|
|
71
|
-
this._peerConnection = new RTCPeerConnection(config || this.config());
|
|
72
|
-
this._dataChannel = this._peerConnection.createDataChannel("tari-data");
|
|
73
|
-
this._signalingServer = new SignaligServer(signalig_server_url);
|
|
74
|
-
this._callbacks = {};
|
|
75
|
-
}
|
|
76
|
-
get token() {
|
|
77
|
-
if (this._walletToken) {
|
|
78
|
-
return this._walletToken;
|
|
79
|
-
}
|
|
80
|
-
return this._signalingServer.token;
|
|
81
|
-
}
|
|
82
|
-
async init(permissions, onConnection) {
|
|
83
|
-
this.onConnection = onConnection;
|
|
84
|
-
await this._signalingServer.initToken(permissions);
|
|
85
|
-
// Setup our receiving end
|
|
86
|
-
this._dataChannel.onmessage = (message) => {
|
|
87
|
-
let response = JSON.parse(message.data);
|
|
88
|
-
console.log('response', response);
|
|
89
|
-
if (!this._callbacks[response.id]) {
|
|
90
|
-
console.error("No callback found for id", response.id);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
// The response should contain id, to identify the Promise.resolve, that is waiting for this result
|
|
94
|
-
let [resolve, reject] = this._callbacks[response.id];
|
|
95
|
-
delete this._callbacks[response.id];
|
|
96
|
-
if (response.payload?.error) {
|
|
97
|
-
reject(new Error(response.payload.error));
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
resolve(response.payload);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
this._dataChannel.onopen = () => {
|
|
104
|
-
// This should be removed before the release, but it's good for debugging.
|
|
105
|
-
console.log("Data channel is open!");
|
|
106
|
-
this.sendMessage({ id: 0, jsonrpc: "2.0", method: "get.token", params: {} }, this._signalingServer.token)
|
|
107
|
-
.then((walletToken) => {
|
|
108
|
-
if (typeof walletToken !== 'string') {
|
|
109
|
-
throw Error('Received invalid JWT from wallet daemon');
|
|
110
|
-
}
|
|
111
|
-
console.log("Wallet JWT received: ", walletToken);
|
|
112
|
-
this._walletToken = walletToken;
|
|
113
|
-
if (this.onConnection) {
|
|
114
|
-
this.onConnection(this);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
};
|
|
118
|
-
this._peerConnection.onicecandidate = (event) => {
|
|
119
|
-
console.log('event', event);
|
|
120
|
-
if (event?.candidate) {
|
|
121
|
-
console.log("ICE ", event.candidate);
|
|
122
|
-
console.log("ICE ", typeof event.candidate);
|
|
123
|
-
// Store the ice candidates, so the other end can add them
|
|
124
|
-
this._signalingServer.storeIceCandidate(event.candidate).then((resp) => {
|
|
125
|
-
// This should be removed before the release, but it's good for debugging.
|
|
126
|
-
console.log("Candidate stored", resp);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
// Create offer
|
|
131
|
-
this._offer = await this._peerConnection.createOffer();
|
|
132
|
-
// Set the offer as our local sdp, at this point it will start getting the ice candidates
|
|
133
|
-
this._peerConnection.setLocalDescription(this._offer);
|
|
134
|
-
// Store the offer so the other end can set it as a remote sdp
|
|
135
|
-
this._signalingServer.storeOffer(this._offer).then((resp) => {
|
|
136
|
-
// This should be removed before the release, but it's good for debugging.
|
|
137
|
-
console.log("Offer stored", resp);
|
|
138
|
-
});
|
|
139
|
-
await this.signalingServerPolling();
|
|
140
|
-
}
|
|
141
|
-
async setAnswer() {
|
|
142
|
-
// This is called once the other end got the offer and ices and created and store an answer and its ice candidates
|
|
143
|
-
// We get its answer sdp
|
|
144
|
-
let sdp = await this._signalingServer.getAnswer();
|
|
145
|
-
// And its ice candidates
|
|
146
|
-
let iceCandidates = await this._signalingServer.getIceCandidates();
|
|
147
|
-
// For us the answer is remote sdp
|
|
148
|
-
let answer = new RTCSessionDescription({ sdp, type: "answer" });
|
|
149
|
-
this._peerConnection.setRemoteDescription(answer);
|
|
150
|
-
// We add all the ice candidates to connect, the other end is doing the same with our ice candidates
|
|
151
|
-
for (const iceCandidate of iceCandidates) {
|
|
152
|
-
this._peerConnection.addIceCandidate(iceCandidate);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
async signalingServerPolling() {
|
|
156
|
-
// no need to keep retrying if we are already connected to the wallet
|
|
157
|
-
if (this._peerConnection.connectionState === "connected") {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
await this.setAnswer();
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
// we don't need to do anything on error, as the execution will be retried later
|
|
165
|
-
console.error(error);
|
|
166
|
-
}
|
|
167
|
-
// try again later
|
|
168
|
-
setTimeout(async () => {
|
|
169
|
-
await this.signalingServerPolling();
|
|
170
|
-
}, 2000);
|
|
171
|
-
}
|
|
172
|
-
isConnected() {
|
|
173
|
-
return this._dataChannel.readyState === "open";
|
|
174
|
-
}
|
|
175
|
-
// If the last parameter has timeout property e.g. {timeout:1000}, it set the timeout for this call.
|
|
176
|
-
async sendMessage(request, token, timeout_secs = null) {
|
|
177
|
-
if (!this.isConnected) {
|
|
178
|
-
throw new Error("WALLET_DAEMON_NOT_CONNECTED");
|
|
179
|
-
}
|
|
180
|
-
// This should be removed before the release, but it's good for debugging.
|
|
181
|
-
console.log(request, 'timeout', timeout_secs);
|
|
182
|
-
return new Promise((resolve, reject) => {
|
|
183
|
-
// We store the resolve callback for this request,
|
|
184
|
-
// so once the data channel receives a response we know where to return the data
|
|
185
|
-
this._callbacks[request.id] = [resolve, reject];
|
|
186
|
-
if (timeout_secs) {
|
|
187
|
-
// If the user set a timeout which set it here so the promise will be rejected if not fulfilled in time.
|
|
188
|
-
setTimeout(() => {
|
|
189
|
-
delete this._callbacks[request.id];
|
|
190
|
-
reject(new Error("Timeout"));
|
|
191
|
-
}, timeout_secs * 1000);
|
|
192
|
-
}
|
|
193
|
-
// Make the actual call to the wallet daemon
|
|
194
|
-
this._dataChannel.send(JSON.stringify({ token, ...request }));
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
// This is our default config, use can set their own stun/turn server in the constructor.
|
|
198
|
-
config() {
|
|
199
|
-
return { iceServers: [{ urls: "stun:stun.l.google.com:19302" }] };
|
|
200
|
-
}
|
|
201
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { transports } from "@tari-project/wallet_jrpc_client";
|
|
2
|
-
import { TariConnection } from "./webrtc";
|
|
3
|
-
export declare class WebRtcRpcTransport implements transports.RpcTransport {
|
|
4
|
-
connection: TariConnection;
|
|
5
|
-
constructor(connection: TariConnection);
|
|
6
|
-
static new(connection: TariConnection): WebRtcRpcTransport;
|
|
7
|
-
token(): string | undefined;
|
|
8
|
-
isConnected(): boolean;
|
|
9
|
-
sendRequest<T>(data: transports.RpcRequest, options: transports.RpcTransportOptions): Promise<T>;
|
|
10
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export class WebRtcRpcTransport {
|
|
2
|
-
connection;
|
|
3
|
-
constructor(connection) {
|
|
4
|
-
this.connection = connection;
|
|
5
|
-
}
|
|
6
|
-
static new(connection) {
|
|
7
|
-
return new WebRtcRpcTransport(connection);
|
|
8
|
-
}
|
|
9
|
-
token() {
|
|
10
|
-
return this.connection.token;
|
|
11
|
-
}
|
|
12
|
-
isConnected() {
|
|
13
|
-
return this.connection.isConnected();
|
|
14
|
-
}
|
|
15
|
-
sendRequest(data, options) {
|
|
16
|
-
return this.connection.sendMessage(data, options.token);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { TariProvider } from "../index";
|
|
2
|
-
import { SubmitTransactionRequest, TransactionResult, SubmitTransactionResponse, VaultBalances, TemplateDefinition, Substate, Account, ListSubstatesResponse } from "../types";
|
|
3
|
-
import UniversalProvider from '@walletconnect/universal-provider';
|
|
4
|
-
import { SubstateType } from "@tari-project/wallet_jrpc_client";
|
|
5
|
-
export declare class WalletConnectTariProvider implements TariProvider {
|
|
6
|
-
providerName: string;
|
|
7
|
-
projectId: string;
|
|
8
|
-
wcProvider: UniversalProvider | null;
|
|
9
|
-
wcSession: any | null;
|
|
10
|
-
constructor(projectId: string);
|
|
11
|
-
connect(): Promise<void>;
|
|
12
|
-
private sendRequest;
|
|
13
|
-
isConnected(): boolean;
|
|
14
|
-
getAccount(): Promise<Account>;
|
|
15
|
-
getSubstate(substate_address: string): Promise<Substate>;
|
|
16
|
-
listSubstates(filter_by_template: string | null, filter_by_type: SubstateType | null, limit: number | null, offset: number | null): Promise<ListSubstatesResponse>;
|
|
17
|
-
createFreeTestCoins(): Promise<Account>;
|
|
18
|
-
submitTransaction(req: SubmitTransactionRequest): Promise<SubmitTransactionResponse>;
|
|
19
|
-
getTransactionResult(transactionId: string): Promise<TransactionResult>;
|
|
20
|
-
getTemplateDefinition(template_address: string): Promise<TemplateDefinition>;
|
|
21
|
-
getPublicKey(branch: string, index: number): Promise<string>;
|
|
22
|
-
getConfidentialVaultBalances(viewKeyId: number, vaultId: string, min: number | null, max: number | null): Promise<VaultBalances>;
|
|
23
|
-
}
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { TransactionStatus, } from "../types";
|
|
2
|
-
import UniversalProvider from '@walletconnect/universal-provider';
|
|
3
|
-
import { WalletConnectModal } from '@walletconnect/modal';
|
|
4
|
-
import { stringToSubstateId, substateIdToString } from "@tari-project/wallet_jrpc_client";
|
|
5
|
-
const walletConnectParams = {
|
|
6
|
-
requiredNamespaces: {
|
|
7
|
-
tari: {
|
|
8
|
-
methods: [
|
|
9
|
-
'tari_getSubstate',
|
|
10
|
-
'tari_getDefaultAccount',
|
|
11
|
-
'tari_getAccountBalances',
|
|
12
|
-
'tari_submitTransaction',
|
|
13
|
-
'tari_getTransactionResult',
|
|
14
|
-
'tari_getTemplate',
|
|
15
|
-
'tari_createKey',
|
|
16
|
-
'tari_viewConfidentialVaultBalance',
|
|
17
|
-
'tari_createFreeTestCoins',
|
|
18
|
-
'tari_listSubstates'
|
|
19
|
-
],
|
|
20
|
-
chains: [
|
|
21
|
-
'tari:devnet',
|
|
22
|
-
],
|
|
23
|
-
events: ['chainChanged", "accountsChanged']
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
export class WalletConnectTariProvider {
|
|
28
|
-
providerName = "WalletConnect";
|
|
29
|
-
projectId;
|
|
30
|
-
wcProvider;
|
|
31
|
-
wcSession;
|
|
32
|
-
constructor(projectId) {
|
|
33
|
-
this.projectId = projectId;
|
|
34
|
-
this.wcProvider = null;
|
|
35
|
-
this.wcSession = null;
|
|
36
|
-
}
|
|
37
|
-
async connect() {
|
|
38
|
-
if (this.wcProvider && this.wcSession)
|
|
39
|
-
return;
|
|
40
|
-
// initialize WalletConnect
|
|
41
|
-
const projectId = this.projectId;
|
|
42
|
-
this.wcProvider = await UniversalProvider.init({
|
|
43
|
-
projectId,
|
|
44
|
-
// TODO: parameterize the relay URL
|
|
45
|
-
relayUrl: 'wss://relay.walletconnect.com'
|
|
46
|
-
});
|
|
47
|
-
// open UI modal with the connection URI
|
|
48
|
-
const { uri, approval } = await this.wcProvider.client.connect(walletConnectParams);
|
|
49
|
-
const walletConnectModal = new WalletConnectModal({
|
|
50
|
-
projectId
|
|
51
|
-
});
|
|
52
|
-
if (uri) {
|
|
53
|
-
walletConnectModal.openModal({ uri });
|
|
54
|
-
}
|
|
55
|
-
// wait for the wallet to approve the connection
|
|
56
|
-
console.log("waiting for session approval from the wallet app");
|
|
57
|
-
const session = await approval();
|
|
58
|
-
// at this point session is open
|
|
59
|
-
console.log("session approved by the wallet");
|
|
60
|
-
this.wcSession = session;
|
|
61
|
-
}
|
|
62
|
-
async sendRequest(method, params) {
|
|
63
|
-
if (!this.wcProvider) {
|
|
64
|
-
throw "WalletConnect provider not initialized";
|
|
65
|
-
}
|
|
66
|
-
if (!this.wcSession) {
|
|
67
|
-
throw "WalletConnect session not initialized";
|
|
68
|
-
}
|
|
69
|
-
const requestResult = await this.wcProvider.client.request({
|
|
70
|
-
topic: this.wcSession.topic,
|
|
71
|
-
chainId: 'tari:devnet',
|
|
72
|
-
request: {
|
|
73
|
-
method,
|
|
74
|
-
params
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
console.log({ requestResult });
|
|
78
|
-
return requestResult;
|
|
79
|
-
}
|
|
80
|
-
isConnected() {
|
|
81
|
-
// TODO: check status in the session
|
|
82
|
-
return this.wcSession !== null;
|
|
83
|
-
}
|
|
84
|
-
async getAccount() {
|
|
85
|
-
const { account, public_key } = await this.sendRequest('tari_getDefaultAccount', {});
|
|
86
|
-
const { balances } = await this.sendRequest('tari_getAccountBalances', { account: { ComponentAddress: account.address.Component }, refresh: false
|
|
87
|
-
});
|
|
88
|
-
return {
|
|
89
|
-
account_id: account.key_index,
|
|
90
|
-
address: account.address.Component,
|
|
91
|
-
public_key,
|
|
92
|
-
// TODO: should be vaults not resources
|
|
93
|
-
resources: balances.map((b) => ({
|
|
94
|
-
type: b.resource_type,
|
|
95
|
-
resource_address: b.resource_address,
|
|
96
|
-
balance: b.balance + b.confidential_balance,
|
|
97
|
-
vault_id: ('Vault' in b.vault_address) ? b.vault_address.Vault : b.vault_address,
|
|
98
|
-
token_symbol: b.token_symbol,
|
|
99
|
-
}))
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
async getSubstate(substate_address) {
|
|
103
|
-
const substateId = stringToSubstateId(substate_address);
|
|
104
|
-
const method = 'tari_getSubstate';
|
|
105
|
-
const params = { substate_id: substateId };
|
|
106
|
-
const { value, record } = await this.sendRequest(method, params);
|
|
107
|
-
return {
|
|
108
|
-
value,
|
|
109
|
-
address: {
|
|
110
|
-
substate_id: substateIdToString(record.substate_id),
|
|
111
|
-
version: record.version
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
async listSubstates(filter_by_template, filter_by_type, limit, offset) {
|
|
116
|
-
const method = 'tari_listSubstates';
|
|
117
|
-
const params = {
|
|
118
|
-
filter_by_template,
|
|
119
|
-
filter_by_type,
|
|
120
|
-
limit,
|
|
121
|
-
offset
|
|
122
|
-
};
|
|
123
|
-
const res = await this.sendRequest(method, params);
|
|
124
|
-
const substates = res.substates.map((s) => ({
|
|
125
|
-
substate_id: substateIdToString(s.substate_id),
|
|
126
|
-
module_name: s.module_name,
|
|
127
|
-
version: s.version,
|
|
128
|
-
template_address: s.template_address
|
|
129
|
-
}));
|
|
130
|
-
return { substates };
|
|
131
|
-
}
|
|
132
|
-
async createFreeTestCoins() {
|
|
133
|
-
const method = 'tari_createFreeTestCoins';
|
|
134
|
-
const params = {
|
|
135
|
-
account: { Name: "template_web" },
|
|
136
|
-
amount: 1000000,
|
|
137
|
-
max_fee: null,
|
|
138
|
-
key_id: 0
|
|
139
|
-
};
|
|
140
|
-
const res = await this.sendRequest(method, params);
|
|
141
|
-
return {
|
|
142
|
-
account_id: res.account.key_index,
|
|
143
|
-
address: res.account.address.Component,
|
|
144
|
-
public_key: res.public_key,
|
|
145
|
-
resources: []
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
async submitTransaction(req) {
|
|
149
|
-
const method = 'tari_submitTransaction';
|
|
150
|
-
const params = {
|
|
151
|
-
transaction: {
|
|
152
|
-
fee_instructions: req.fee_instructions,
|
|
153
|
-
instructions: req.instructions,
|
|
154
|
-
inputs: req.required_substates.map((s) => ({
|
|
155
|
-
// TODO: Hmm The bindings want a SubstateId object, but the wallet only wants a string. Any is used to skip type checking here
|
|
156
|
-
substate_id: s.substate_id,
|
|
157
|
-
version: s.version
|
|
158
|
-
})),
|
|
159
|
-
min_epoch: null,
|
|
160
|
-
max_epoch: null,
|
|
161
|
-
},
|
|
162
|
-
signing_key_index: req.account_id,
|
|
163
|
-
autofill_inputs: [],
|
|
164
|
-
detect_inputs: true,
|
|
165
|
-
proof_ids: [],
|
|
166
|
-
};
|
|
167
|
-
const res = await this.sendRequest(method, params);
|
|
168
|
-
return { transaction_id: res.transaction_id };
|
|
169
|
-
}
|
|
170
|
-
async getTransactionResult(transactionId) {
|
|
171
|
-
const res = await this.sendRequest('tari_getTransactionResult', { transaction_id: transactionId });
|
|
172
|
-
return {
|
|
173
|
-
transaction_id: transactionId,
|
|
174
|
-
status: convertStringToTransactionStatus(res.status),
|
|
175
|
-
result: res.result,
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
async getTemplateDefinition(template_address) {
|
|
179
|
-
let resp = await this.sendRequest('tari_getTemplate', { template_address });
|
|
180
|
-
return resp.template_definition;
|
|
181
|
-
}
|
|
182
|
-
async getPublicKey(branch, index) {
|
|
183
|
-
const res = await this.sendRequest('tari_createKey', { branch: branch, specific_index: index });
|
|
184
|
-
return res.public_key;
|
|
185
|
-
}
|
|
186
|
-
async getConfidentialVaultBalances(viewKeyId, vaultId, min, max) {
|
|
187
|
-
const method = 'tari_viewConfidentialVaultBalance';
|
|
188
|
-
const params = {
|
|
189
|
-
view_key_id: viewKeyId,
|
|
190
|
-
vault_id: vaultId,
|
|
191
|
-
minimum_expected_value: min,
|
|
192
|
-
maximum_expected_value: max,
|
|
193
|
-
};
|
|
194
|
-
const res = await this.sendRequest(method, params);
|
|
195
|
-
return { balances: res.balances };
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
function convertStringToTransactionStatus(status) {
|
|
199
|
-
switch (status) {
|
|
200
|
-
case "New":
|
|
201
|
-
return TransactionStatus.New;
|
|
202
|
-
case "DryRun":
|
|
203
|
-
return TransactionStatus.DryRun;
|
|
204
|
-
case "Pending":
|
|
205
|
-
return TransactionStatus.Pending;
|
|
206
|
-
case "Accepted":
|
|
207
|
-
return TransactionStatus.Accepted;
|
|
208
|
-
case "Rejected":
|
|
209
|
-
return TransactionStatus.Rejected;
|
|
210
|
-
case "InvalidTransaction":
|
|
211
|
-
return TransactionStatus.InvalidTransaction;
|
|
212
|
-
case "OnlyFeeAccepted":
|
|
213
|
-
return TransactionStatus.OnlyFeeAccepted;
|
|
214
|
-
default:
|
|
215
|
-
throw new Error(`Unknown status: ${status}`);
|
|
216
|
-
}
|
|
217
|
-
}
|