forked from arconnectio/ArConnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
185 lines (166 loc) · 4.57 KB
/
index.d.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import { SignatureOptions } from "arweave/node/lib/crypto/crypto-interface";
import Transaction from "arweave/node/lib/transaction";
/**
* Arweave wallet declarations
*/
declare global {
interface Window {
arweaveWallet: {
/**
* Name of the wallet the API was provided by.
*/
walletName: string;
/**
* Connect to ArConnect and request permissions. This function can always be
* called again if you want to request more permissions for your site.
*
* @param permissions
* @param appInfo
*/
connect(
permissions: PermissionType[],
appInfo?: AppInfo,
gateway?: GatewayConfig
): Promise<void>;
/**
* Disconnect from ArConnect. Removes all permissions from your site.
*/
disconnect(): Promise<void>;
/**
* Get the currently used wallet's address in the extension.
*
* @returns Promise of wallet address string
*/
getActiveAddress(): Promise<string>;
/**
* Get all addresses added to the ArConnect extension
*
* @returns Promise of a list of the added wallets' addresses.
*/
getAllAddresses(): Promise<string[]>;
/**
* Get wallet names for addresses.
*
* @returns Promise of an object with addresses and wallet names
*/
getWalletNames(): Promise<{ [addr: string]: string }>;
/**
* Sign a transaction.
*
* @param transaction A valid Arweave transaction without a wallet keyfile added to it
* @param options Arweave signing options
*
* @returns Promise of a signed transaction instance
*/
sign(
transaction: Transaction,
options?: SignatureOptions
): Promise<Transaction>;
/**
* Get the permissions allowed for you site by the user.
*
* @returns Promise of a list of permissions allowed for your dApp.
*/
getPermissions(): Promise<PermissionType[]>;
/**
* Encrypt a string, using the user's wallet.
*
* @param data String to encrypt
* @param options Encrypt options
*
* @returns Promise of the encrypted string
*/
encrypt(
data: string,
options: {
algorithm: string;
hash: string;
salt?: string;
}
): Promise<Uint8Array>;
/**
* Decrypt a string encrypted with the user's wallet.
*
* @param data `Uint8Array` data to decrypt to a string
* @param options Decrypt options
*
* @returns Promise of the decrypted string
*/
decrypt(
data: Uint8Array,
options: {
algorithm: string;
hash: string;
salt?: string;
}
): Promise<string>;
/**
* Get the user's custom Arweave config set in the extension
*
* @returns Promise of the user's Arweave config
*/
getArweaveConfig(): Promise<{
host: string;
port: number;
protocol: "http" | "https";
}>;
/**
* Get the signature for data array
*
* @param data `Uint8Array` data to get the signature for
* @param algorithm
*
* @returns Promise of signature
*/
signature(
data: Uint8Array,
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/sign#parameters
algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams
): Promise<Uint8Array>;
/**
* Get the user's active public key, from their wallet
*
* @returns Promise of the active public key
*/
getActivePublicKey(): Promise<string>;
/**
* Dispatch an Arweave transaction (preferably bundled)
*
* @param transaction Transaction to dispatch
* @returns Dispatched transaction ID and type
*/
dispatch(transaction: Transaction): Promise<DispatchResult>;
};
}
interface WindowEventMap {
walletSwitch: CustomEvent<{ address: string }>;
arweaveWalletLoaded: CustomEvent<{}>;
}
}
/**
* Arweave wallet permission types
*/
export type PermissionType =
| "ACCESS_ADDRESS"
| "ACCESS_PUBLIC_KEY"
| "ACCESS_ALL_ADDRESSES"
| "SIGN_TRANSACTION"
| "ENCRYPT"
| "DECRYPT"
| "SIGNATURE"
| "ACCESS_ARWEAVE_CONFIG"
| "DISPATCH";
export interface DispatchResult {
id: string;
type?: "BASE" | "BUNDLED";
}
export interface AppInfo {
name?: string;
logo?: string;
}
export interface GatewayConfig {
host: string;
port: number;
protocol: "http" | "https";
}
export {};