-
Notifications
You must be signed in to change notification settings - Fork 55
/
types.ts
125 lines (107 loc) · 4.18 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { Bytes, Cbor, Paginate } from '../types';
import { Cardano } from '@cardano-sdk/core';
/**
* If `amount` is `undefined`, this shall return a list of all UTxOs (unspent transaction outputs)
* controlled by the wallet.
*
* If `amount` is not `undefined`, this request shall be limited to just the UTxOs that are required
* to reach the combined ADA/multi-asset value target specified in `amount`,
* and if this cannot be attained, `undefined` shall be returned.
*
* The results can be further paginated by `paginate` if it is not `undefined`.
*
* Errors: `ApiError` | `PaginateError`
*/
export type GetUtxos = (amount?: Cbor, paginate?: Paginate) => Promise<Cardano.Utxo[] | undefined>;
/**
* Returns the total balance available of the wallet.
*
* This is the same as summing the results of `api.getUtxos()`, but it is both useful to dApps
* and likely already maintained by the implementing wallet in a more efficient manner
* so it has been included in the API as well.
*
* Errors: `ApiError`
*/
export type GetBalance = () => Promise<Cbor>;
/**
* Returns a list of all used (included in some on-chain transaction) addresses controlled by the wallet.
*
* The results can be further paginated by `paginate` if it is not `undefined`.
*
* Errors: `ApiError` | `PaginateError`
*/
export type GetUsedAddresses = (paginate?: Paginate) => Promise<Cbor[]>;
/**
* Returns a list of unused addresses controlled by the wallet.
*
* Errors: `ApiError`
*/
export type GetUnusedAddresses = () => Promise<Cbor[]>;
/**
* Returns an address owned by the wallet that should be used as a change address to return
* leftover assets during transaction creation back to the connected wallet.
*
* This can be used as a generic receive address as well.
*
* Errors: `ApiError`
*/
export type GetChangeAddress = () => Promise<Cbor>;
/**
* Returns the reward addresses owned by the wallet. This can return multiple addresses e.g. CIP-0018.
*
* Errors: `ApiError`
*/
export type GetRewardAddresses = () => Promise<Cbor[]>;
/**
* Requests that a user sign the unsigned portions of the supplied transaction.
*
* The wallet should ask the user for permission, and if given,
* try to sign the supplied body and return a signed transaction.
*
* If `partialSign` is `true`, the wallet only tries to sign what it can.
*
* If `partialSign` is `false` and the wallet could not sign the entire transaction,
* `TxSignError` shall be returned with the `ProofGeneration` code.
*
* Likewise if the user declined in either case it shall return the `UserDeclined` code.
*
* Only the portions of the witness set that were signed as a result of this call are
* returned to encourage dApps to verify the contents returned by this endpoint while building the final transaction.
*
* Errors: `ApiError` | `TxSignError`
*/
export type SignTx = (tx: Cbor, partialSign?: Boolean) => Promise<Cbor>;
/**
* This endpoint utilizes the CIP-0008 signing spec for standardization/safety reasons.
*
* It allows the dApp to request the user to sign data conforming to said spec.
*
* The user's consent should be requested and the details of `sig_structure` shown to them in an informative way.
*
* Please refer to the CIP-0008 spec for details on how to construct the sig structure.
*
* Errors: `ApiError` | `DataSignError`
*/
export type SignData = (addr: Cbor, sigStructure: Cbor) => Promise<Bytes>;
/**
* As wallets should already have this ability, we allow dApps to request that a transaction be sent through it.
*
* If the wallet accepts the transaction and tries to send it, it shall return the transaction id for the dApp to track.
*
* The wallet is free to return the `TxSendError` with code `Refused` if they do not wish to send it,
* or `Failure` if there was an error in sending it (e.g. preliminary checks failed on signatures).
*
* Errors: `ApiError` | `TxSendError`
*/
export type SubmitTx = (tx: Cbor) => Promise<string>;
export interface WalletApi {
getUtxos: GetUtxos;
getBalance: GetBalance;
getUsedAddresses: GetUsedAddresses;
getUnusedAddresses: GetUnusedAddresses;
getChangeAddress: GetChangeAddress;
getRewardAddresses: GetRewardAddresses;
signTx: SignTx;
signData: SignData;
submitTx: SubmitTx;
}