llama-pay-sdk 4.0.0 → 4.0.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.
Files changed (146) hide show
  1. package/lib/CashoutClient.d.ts +22 -0
  2. package/lib/CashoutClient.d.ts.map +1 -0
  3. package/lib/CashoutClient.js +95 -0
  4. package/lib/CashoutClient.js.map +1 -0
  5. package/lib/HttpClient.d.ts +28 -0
  6. package/lib/HttpClient.d.ts.map +1 -0
  7. package/lib/HttpClient.js +69 -0
  8. package/lib/HttpClient.js.map +1 -0
  9. package/lib/MerapiClient.d.ts +133 -0
  10. package/lib/MerapiClient.d.ts.map +1 -0
  11. package/lib/MerapiClient.js +311 -0
  12. package/lib/MerapiClient.js.map +1 -0
  13. package/lib/crypto.d.ts +24 -0
  14. package/lib/crypto.d.ts.map +1 -0
  15. package/lib/crypto.js +93 -0
  16. package/lib/crypto.js.map +1 -0
  17. package/lib/device-info.d.ts +5 -0
  18. package/lib/device-info.d.ts.map +1 -0
  19. package/lib/device-info.js +37 -0
  20. package/lib/device-info.js.map +1 -0
  21. package/lib/dora/DoraApiClient.d.ts +30 -0
  22. package/lib/dora/DoraApiClient.d.ts.map +1 -0
  23. package/lib/dora/DoraApiClient.js +34 -0
  24. package/lib/dora/DoraApiClient.js.map +1 -0
  25. package/lib/dora/index.d.ts +2 -0
  26. package/lib/dora/index.d.ts.map +1 -0
  27. package/lib/dora/index.js +6 -0
  28. package/lib/dora/index.js.map +1 -0
  29. package/lib/dora/types/Transaction.d.ts +30 -0
  30. package/lib/dora/types/Transaction.d.ts.map +1 -0
  31. package/lib/dora/types/Transaction.js +3 -0
  32. package/lib/dora/types/Transaction.js.map +1 -0
  33. package/lib/erc20Abi.d.ts +39 -0
  34. package/lib/erc20Abi.d.ts.map +1 -0
  35. package/lib/erc20Abi.js +226 -0
  36. package/lib/erc20Abi.js.map +1 -0
  37. package/lib/index.d.ts +19 -0
  38. package/lib/index.d.ts.map +1 -0
  39. package/lib/index.js +45 -0
  40. package/lib/index.js.map +1 -0
  41. package/lib/models/Balance.d.ts +16 -0
  42. package/lib/models/Balance.d.ts.map +1 -0
  43. package/lib/models/Balance.js +3 -0
  44. package/lib/models/Balance.js.map +1 -0
  45. package/lib/models/FeatureFlags.d.ts +5 -0
  46. package/lib/models/FeatureFlags.d.ts.map +1 -0
  47. package/lib/models/FeatureFlags.js +3 -0
  48. package/lib/models/FeatureFlags.js.map +1 -0
  49. package/lib/models/IBinInfo.d.ts +25 -0
  50. package/lib/models/IBinInfo.d.ts.map +1 -0
  51. package/lib/models/IBinInfo.js +3 -0
  52. package/lib/models/IBinInfo.js.map +1 -0
  53. package/lib/models/IMultisigTransaction.d.ts +41 -0
  54. package/lib/models/IMultisigTransaction.d.ts.map +1 -0
  55. package/lib/models/IMultisigTransaction.js +3 -0
  56. package/lib/models/IMultisigTransaction.js.map +1 -0
  57. package/lib/models/IMultisigWallet.d.ts +36 -0
  58. package/lib/models/IMultisigWallet.d.ts.map +1 -0
  59. package/lib/models/IMultisigWallet.js +3 -0
  60. package/lib/models/IMultisigWallet.js.map +1 -0
  61. package/lib/models/ITokenInfo.d.ts +10 -0
  62. package/lib/models/ITokenInfo.d.ts.map +1 -0
  63. package/lib/models/ITokenInfo.js +3 -0
  64. package/lib/models/ITokenInfo.js.map +1 -0
  65. package/lib/models/IUser.d.ts +10 -0
  66. package/lib/models/IUser.d.ts.map +1 -0
  67. package/lib/models/IUser.js +3 -0
  68. package/lib/models/IUser.js.map +1 -0
  69. package/lib/models/LinkedCard.d.ts +6 -0
  70. package/lib/models/LinkedCard.d.ts.map +1 -0
  71. package/lib/models/LinkedCard.js +3 -0
  72. package/lib/models/LinkedCard.js.map +1 -0
  73. package/lib/models/ResponseWrapper.d.ts +9 -0
  74. package/lib/models/ResponseWrapper.d.ts.map +1 -0
  75. package/lib/models/ResponseWrapper.js +3 -0
  76. package/lib/models/ResponseWrapper.js.map +1 -0
  77. package/lib/models/SimpleMultisigTransactionData.d.ts +29 -0
  78. package/lib/models/SimpleMultisigTransactionData.d.ts.map +1 -0
  79. package/lib/models/SimpleMultisigTransactionData.js +3 -0
  80. package/lib/models/SimpleMultisigTransactionData.js.map +1 -0
  81. package/lib/models/Transaction.d.ts +13 -0
  82. package/lib/models/Transaction.d.ts.map +1 -0
  83. package/lib/models/Transaction.js +3 -0
  84. package/lib/models/Transaction.js.map +1 -0
  85. package/lib/models/Wallet.d.ts +15 -0
  86. package/lib/models/Wallet.d.ts.map +1 -0
  87. package/lib/models/Wallet.js +3 -0
  88. package/lib/models/Wallet.js.map +1 -0
  89. package/lib/models/WalletAccount.d.ts +8 -0
  90. package/lib/models/WalletAccount.d.ts.map +1 -0
  91. package/lib/models/WalletAccount.js +3 -0
  92. package/lib/models/WalletAccount.js.map +1 -0
  93. package/lib/models/cashout/Atm.d.ts +19 -0
  94. package/lib/models/cashout/Atm.d.ts.map +1 -0
  95. package/lib/models/cashout/Atm.js +3 -0
  96. package/lib/models/cashout/Atm.js.map +1 -0
  97. package/lib/models/cashout/CashoutLimits.d.ts +11 -0
  98. package/lib/models/cashout/CashoutLimits.d.ts.map +1 -0
  99. package/lib/models/cashout/CashoutLimits.js +3 -0
  100. package/lib/models/cashout/CashoutLimits.js.map +1 -0
  101. package/lib/models/cashout/CashoutRequest.d.ts +16 -0
  102. package/lib/models/cashout/CashoutRequest.d.ts.map +1 -0
  103. package/lib/models/cashout/CashoutRequest.js +3 -0
  104. package/lib/models/cashout/CashoutRequest.js.map +1 -0
  105. package/lib/models/cashout/CashoutResponse.d.ts +15 -0
  106. package/lib/models/cashout/CashoutResponse.d.ts.map +1 -0
  107. package/lib/models/cashout/CashoutResponse.js +3 -0
  108. package/lib/models/cashout/CashoutResponse.js.map +1 -0
  109. package/{src/models/cashout/CashoutStatus.ts → lib/models/cashout/CashoutStatus.d.ts} +3 -2
  110. package/lib/models/cashout/CashoutStatus.d.ts.map +1 -0
  111. package/lib/models/cashout/CashoutStatus.js +20 -0
  112. package/lib/models/cashout/CashoutStatus.js.map +1 -0
  113. package/lib/models/cashout/CreateCashoutResponse.d.ts +8 -0
  114. package/lib/models/cashout/CreateCashoutResponse.d.ts.map +1 -0
  115. package/lib/models/cashout/CreateCashoutResponse.js +3 -0
  116. package/lib/models/cashout/CreateCashoutResponse.js.map +1 -0
  117. package/package.json +4 -1
  118. package/src/CashoutClient.ts +0 -139
  119. package/src/HttpClient.ts +0 -116
  120. package/src/MerapiClient.ts +0 -526
  121. package/src/crypto.ts +0 -144
  122. package/src/device-info.ts +0 -38
  123. package/src/dora/DoraApiClient.ts +0 -58
  124. package/src/dora/index.ts +0 -6
  125. package/src/dora/types/Transaction.ts +0 -31
  126. package/src/erc20Abi.ts +0 -222
  127. package/src/index.ts +0 -32
  128. package/src/models/Balance.ts +0 -16
  129. package/src/models/FeatureFlags.ts +0 -4
  130. package/src/models/IBinInfo.ts +0 -24
  131. package/src/models/IMultisigTransaction.ts +0 -48
  132. package/src/models/IMultisigWallet.ts +0 -40
  133. package/src/models/ITokenInfo.ts +0 -9
  134. package/src/models/IUser.ts +0 -9
  135. package/src/models/LinkedCard.ts +0 -4
  136. package/src/models/ResponseWrapper.ts +0 -8
  137. package/src/models/SimpleMultisigTransactionData.ts +0 -28
  138. package/src/models/Transaction.ts +0 -12
  139. package/src/models/Wallet.ts +0 -17
  140. package/src/models/WalletAccount.ts +0 -7
  141. package/src/models/cashout/Atm.ts +0 -23
  142. package/src/models/cashout/CashoutLimits.ts +0 -10
  143. package/src/models/cashout/CashoutRequest.ts +0 -16
  144. package/src/models/cashout/CashoutResponse.ts +0 -14
  145. package/src/models/cashout/CreateCashoutResponse.ts +0 -7
  146. package/tsconfig.json +0 -18
@@ -1,526 +0,0 @@
1
- import axios, { AxiosInstance, AxiosResponse } from 'axios'
2
- import { getBundleId, getDeviceId, getUserAgent } from './device-info'
3
- import { BalanceResponse } from './models/Balance'
4
- import { Atm } from './models/cashout/Atm'
5
- import { CashoutRequest } from './models/cashout/CashoutRequest'
6
- import { CreateCashoutResponse } from './models/cashout/CreateCashoutResponse'
7
- import { FeatureFlags } from './models/FeatureFlags'
8
- import {
9
- ICreditCardMultisigWallet,
10
- IGeneralMultisigWallet
11
- } from './models/IMultisigWallet'
12
- import { ITokenInfo } from './models/ITokenInfo'
13
- import { IMultisigTransaction } from './models/IMultisigTransaction'
14
- import { IUser } from './models/IUser'
15
- import ResponseWrapper from './models/ResponseWrapper'
16
- import { CashoutLimits } from './models/cashout/CashoutLimits'
17
- import CashoutResponse from './models/cashout/CashoutResponse'
18
- import { Transaction } from './models/Transaction'
19
- import { LinkedCard } from './models/LinkedCard'
20
- import { WalletAccount } from './models/WalletAccount'
21
-
22
- type AuthTokenProvider = () => Promise<string | null>
23
-
24
- type Response<T> = {
25
- result: 'ok' | 'error'
26
- error: {
27
- code: string
28
- server_message: string
29
- } | null
30
- data: T
31
- }
32
-
33
- export class MerapiClient {
34
- http: AxiosInstance
35
-
36
- private deviceId?: string
37
- private userAgent?: string
38
- private bundleId?: string
39
-
40
- afterRequestCallback?: (
41
- responseBody: any,
42
- response: AxiosResponse
43
- ) => void | Promise<void>
44
-
45
- authTokenProvider?: AuthTokenProvider
46
-
47
- constructor(params: { baseUrl: string; clientId: string }) {
48
- this.http = axios.create({
49
- baseURL: params.baseUrl,
50
- timeout: 30 * 1000,
51
- headers: {
52
- 'Content-Type': 'application/json',
53
- Accept: 'application/json',
54
- 'X-Client-Id': params.clientId
55
- },
56
- validateStatus: () => true
57
- })
58
-
59
- this.http.interceptors.request.use(
60
- async (config) => {
61
- config.headers = config.headers ?? {}
62
-
63
- if (!this.deviceId) this.deviceId = await getDeviceId()
64
- if (!this.userAgent) this.userAgent = await getUserAgent()
65
- if (!this.bundleId) this.bundleId = await getBundleId()
66
-
67
- const token = await this.authTokenProvider?.()
68
-
69
- if (token) config.headers.Authorization = token
70
- if (this.deviceId) config.headers['X-Device-ID'] = this.deviceId
71
- if (this.userAgent)
72
- config.headers['User-Agent'] = this.userAgent
73
- if (this.bundleId) config.headers['X-Bundle-Id'] = this.bundleId
74
-
75
- return config
76
- },
77
- (error) => Promise.reject(error)
78
- )
79
-
80
- this.http.interceptors.response.use(
81
- (response) => {
82
- const body = response.data
83
-
84
- this.afterRequestCallback?.call(null, body, response)
85
-
86
- const errorMessage =
87
- body?.error?.server_message || body?.error?.code
88
- if (errorMessage) {
89
- return Promise.reject(new Error(errorMessage))
90
- }
91
- return response
92
- },
93
- (error) => {
94
- return Promise.reject(error)
95
- }
96
- )
97
- }
98
-
99
- setAuthTokenProvider(provider: AuthTokenProvider) {
100
- this.authTokenProvider = provider
101
- }
102
-
103
- generateLoginCode = async (params: {
104
- contact: string
105
- password?: string
106
- }): Promise<void> => {
107
- await this.http.post('/wallet/login/code', params)
108
- }
109
-
110
- confirmLoginCode = async (params: {
111
- contact: string
112
- code: string
113
- }): Promise<{
114
- sessionKey: string
115
- }> => {
116
- return this.http
117
- .post<
118
- Response<{ sessionKey: string }>
119
- >('/wallet/login/confirm', params)
120
- .then((res) => res.data.data)
121
- }
122
-
123
- getCurrentUser = async (): Promise<IUser> => {
124
- return this.http.get<IUser>('/wallet/users/me').then((res) => res.data)
125
- }
126
-
127
- updateProfile = async (params: {
128
- firstName: string
129
- lastName: string
130
- }): Promise<IUser> => {
131
- return this.http
132
- .post<IUser>('/wallet/profile', {
133
- first_name: params.firstName,
134
- second_name: params.lastName
135
- })
136
- .then((res) => res.data)
137
- }
138
-
139
- getBalances = (
140
- address: string,
141
- tokens: {
142
- tokenAddress: string | null
143
- }[]
144
- ): Promise<BalanceResponse[]> => {
145
- return this.http
146
- .post(`/wallet/blockchain/${address}/get-balance`, {
147
- tokens
148
- })
149
- .then((res) => res.data)
150
- }
151
-
152
- setUserPublicAddress = async (params: { address: string }) => {
153
- await this.http.post('/wallet/users/set-address', params)
154
- }
155
-
156
- getDefaultTokens = (): Promise<ITokenInfo[]> => {
157
- return this.http
158
- .get<ITokenInfo[]>(`/wallet/blockchain/tokens`)
159
- .then((res) => res.data)
160
- }
161
-
162
- createMultisigWallet = (params: {
163
- name: string
164
- signers: string[]
165
- threshold: number
166
- }): Promise<IGeneralMultisigWallet> => {
167
- return this.http
168
- .post<IGeneralMultisigWallet>('/wallet/wallets', params)
169
- .then((res) => res.data)
170
- }
171
-
172
- acceptMultisigWallet = async (walletId: string) => {
173
- await this.http.post(`/wallet/wallets/${walletId}/accept`, { walletId })
174
- }
175
-
176
- getMultisigWallets = (): Promise<IGeneralMultisigWallet[]> => {
177
- return this.http
178
- .get<IGeneralMultisigWallet[]>('/wallet/wallets')
179
- .then((res) => res.data)
180
- }
181
-
182
- createMultisigTransaction = (params: {
183
- walletId: string
184
- assetType: 'native' | 'erc20'
185
- to: string
186
- amount: string
187
- tokenAddress: string | null
188
- remark: string | null
189
- }): Promise<IMultisigTransaction> => {
190
- return this.http
191
- .post<IMultisigTransaction>('/wallet/tx', params)
192
- .then((res) => res.data)
193
- }
194
-
195
- getMultisigWalletTransactions = (
196
- walletId: string
197
- ): Promise<IMultisigTransaction[]> => {
198
- return this.http
199
- .get<IMultisigTransaction[]>(`/wallet/wallets/${walletId}/tx`)
200
- .then((res) => res.data)
201
- }
202
-
203
- getMultisigWalletTransaction = async (
204
- txId: string
205
- ): Promise<IMultisigTransaction> => {
206
- return this.http
207
- .get<IMultisigTransaction>(`/wallet/tx/${txId}`)
208
- .then((res) => res.data)
209
- }
210
-
211
- addMultisigTxSignature = (
212
- txId: string,
213
- data: { txid: string; address: string; signature: string }
214
- ): Promise<IMultisigTransaction> => {
215
- return this.http
216
- .post<IMultisigTransaction>(`/wallet/tx/${txId}/signature`, data)
217
- .then((res) => res.data)
218
- }
219
-
220
- executeTransaction = (txId: string): Promise<IMultisigTransaction> => {
221
- return this.http
222
- .post<IMultisigTransaction>(`/wallet/tx/${txId}/execute`, {
223
- txid: txId
224
- })
225
- .then((res) => res.data)
226
- }
227
-
228
- getCCWallet = async (): Promise<ICreditCardMultisigWallet | null> => {
229
- const response =
230
- await this.http.get<ICreditCardMultisigWallet>('/wallet/ccwallet')
231
- const wallet = response.data
232
- if (wallet && Object.keys(wallet).length > 0) {
233
- return wallet as ICreditCardMultisigWallet
234
- }
235
- return null
236
- }
237
-
238
- getCCWalletTransactions = (
239
- walletId: string
240
- ): Promise<IMultisigTransaction[]> => {
241
- return this.http
242
- .get<IMultisigTransaction[]>(`/wallet/ccwallet/${walletId}/tx`)
243
- .then((res) => res.data)
244
- }
245
-
246
- createCCWallet = (params: {
247
- pan: string
248
- }): Promise<ICreditCardMultisigWallet> => {
249
- return this.http
250
- .post<ICreditCardMultisigWallet>('/wallet/ccwallet', params)
251
- .then((res) => res.data)
252
- }
253
-
254
- executePosTransaction = (params: {
255
- destination: string
256
- panHash: string
257
- amount: string
258
- remark?: string
259
- merchant: string
260
- confirmations?: number
261
- }): Promise<IMultisigTransaction> => {
262
- return this.http
263
- .post<IMultisigTransaction>('/wallet/tx/pos', params)
264
- .then((res) => res.data)
265
- }
266
-
267
- getTokenInfo = async (tokenAddress: string): Promise<ITokenInfo | null> => {
268
- return this.http
269
- .get<ITokenInfo | null>(
270
- `/wallet/blockchain/${tokenAddress}/token-info`
271
- )
272
- .then((res) => res.data)
273
- }
274
-
275
- getFeatureFlags = async (): Promise<FeatureFlags> => {
276
- // TODO: remove mock
277
- return {
278
- multisignatureWallet: true,
279
- paymentWallet: true
280
- }
281
- }
282
-
283
- markTopup = async (
284
- walletId: string,
285
- hash: string
286
- ): Promise<IMultisigTransaction> => {
287
- return this.http
288
- .post<IMultisigTransaction>(`/wallet/ccwallet/${walletId}/topup`, {
289
- walletId,
290
- hash
291
- })
292
- .then((res) => res.data)
293
- }
294
-
295
- // cashout
296
-
297
- getCashoutLimits = async (atmId: string): Promise<CashoutLimits> => {
298
- return this.http
299
- .get<CashoutLimits>(`/cashout/limits?atm_id=${atmId}`)
300
- .then((res) => res.data)
301
- }
302
-
303
- getAtmList = async () => {
304
- const response =
305
- await this.http.get<ResponseWrapper<{ items: Atm[] }>>(
306
- '/cashout/atm/list'
307
- )
308
- return response.data.data.items
309
- }
310
-
311
- sendVerificationWord = async (params: {
312
- firstName: string
313
- lastName: string
314
- phoneNumber: string
315
- }) => {
316
- const data = new URLSearchParams()
317
- data.append('first_name', params.firstName)
318
- data.append('last_name', params.lastName)
319
- data.append('phone_number', params.phoneNumber)
320
- data.append('word_code', '1')
321
- data.append('_t', new Date().getTime().toString())
322
-
323
- await this.http.post('/cashout/pcode/verify', data, {
324
- headers: {
325
- 'Content-Type': 'application/x-www-form-urlencoded'
326
- }
327
- })
328
- }
329
-
330
- createCashoutRequest = async (params: {
331
- atmId: string
332
- amount: string
333
- }): Promise<CreateCashoutResponse> => {
334
- const data = new URLSearchParams()
335
- data.append('atm_id', params.atmId)
336
- data.append('amount', params.amount)
337
- data.append('_t', new Date().getTime().toString())
338
-
339
- const response = await this.http.post<
340
- ResponseWrapper<{
341
- items: [
342
- {
343
- secure_code: string
344
- address: string
345
- usd_amount: number
346
- btc_amount: number
347
- btc_whole_unit_price: number
348
- }
349
- ]
350
- }>
351
- >('/cashout/pcode', data, {
352
- headers: {
353
- 'Content-Type': 'application/x-www-form-urlencoded'
354
- }
355
- })
356
- const result = response.data.data.items[0]
357
-
358
- return {
359
- secureCode: result.secure_code,
360
- address: result.address,
361
- usdAmount: result.usd_amount,
362
- btcAmount: result.btc_amount,
363
- btcWholeUnitPrice: result.btc_whole_unit_price
364
- }
365
- }
366
-
367
- getCashOutRequest = async (cashCode: string): Promise<CashoutRequest> => {
368
- const response = await this.http.get<
369
- ResponseWrapper<{
370
- items: CashoutResponse[]
371
- }>
372
- >(`/cashout/pcode/${cashCode}`)
373
- const result = response.data.data.items[0]
374
- return buildCashoutItem(result)
375
- }
376
-
377
- getCashOutRequests = async (): Promise<CashoutRequest[]> => {
378
- const response = await this.http.get<
379
- ResponseWrapper<{
380
- items: []
381
- }>
382
- >('/cashout/pcodes')
383
- const result = response.data.data.items
384
- return result.map(buildCashoutItem)
385
- }
386
-
387
- linkCardToAddress = async (params: {
388
- address: string
389
- cardhash: string
390
- lastDigits: string
391
- }): Promise<void> => {
392
- await this.http.post<ResponseWrapper<{ items: [{}] }>>(
393
- '/cashout/card/link',
394
- params
395
- )
396
- }
397
-
398
- getAddressByCardHash = async (
399
- cardhash: string
400
- ): Promise<string | undefined> => {
401
- const response = await this.http.get<
402
- ResponseWrapper<{ items: [{ address: string } | undefined] }>
403
- >(`/cashout/card/link?cardhash=${cardhash}`)
404
- return response.data.data.items[0]?.address
405
- }
406
-
407
- getLinkedCardsCount = async (): Promise<number> => {
408
- const response = await this.http.post<
409
- ResponseWrapper<{ items: [{ linked_cards_count: number }] }>
410
- >('/cashout/card/link/count')
411
- return response.data.data.items[0].linked_cards_count
412
- }
413
-
414
- getLinkedCards = async (): Promise<LinkedCard[]> => {
415
- const response = await this.http.get<
416
- ResponseWrapper<{
417
- items: {
418
- last_digits: string | null
419
- address: string
420
- }[]
421
- }>
422
- >('/cashout/card/links')
423
- return response.data.data.items.map((item) => {
424
- return {
425
- address: item.address,
426
- lastDigits: item.last_digits
427
- }
428
- })
429
- }
430
-
431
- submitTransaction = async (params: {
432
- transaction: string
433
- }): Promise<{
434
- hash: string
435
- }> => {
436
- const response = await this.http.post<{ hash: string }>(
437
- '/wallet/transaction',
438
- params
439
- )
440
- return response.data
441
- }
442
-
443
- getRpcUrl = async (): Promise<string> => {
444
- const response = await this.http.post<{ nodeUrl: string }>(
445
- '/wallet/service/info'
446
- )
447
- return response.data.nodeUrl
448
- }
449
-
450
- getTransactions = async (): Promise<Transaction[]> => {
451
- const response = await this.http.get<Transaction[]>(
452
- '/wallet/transactions'
453
- )
454
- return response.data
455
- }
456
-
457
- // wallet accounts
458
-
459
- createAccount = async (params: {
460
- address: string
461
- index: number
462
- label?: string
463
- }): Promise<void> => {
464
- await this.http.post('/wallet/account', {
465
- address: params.address,
466
- account_index: params.index,
467
- optional_account_label: params.label
468
- })
469
- }
470
-
471
- deleteAccount = async (params: { accountIndex: number }): Promise<void> => {
472
- await this.http.delete('/wallet/account', {
473
- data: { account_index: params.accountIndex }
474
- })
475
- }
476
-
477
- setAccountLabel = async (params: {
478
- accountIndex: string
479
- label: string
480
- }): Promise<void> => {
481
- await this.http.post('/wallet/account/label', {
482
- account_index: params.accountIndex,
483
- account_label: params.label
484
- })
485
- }
486
-
487
- getAccounts = async (): Promise<WalletAccount[]> => {
488
- const response = await this.http.get<
489
- ResponseWrapper<{
490
- items: {
491
- account_index: 0
492
- account_label: string
493
- address: string
494
- created_at: string
495
- updated_at: string | null
496
- }[]
497
- }>
498
- >('/wallet/accounts')
499
- return response.data.data.items.map((item) => {
500
- return {
501
- index: item.account_index,
502
- address: item.address,
503
- label: item.account_label,
504
- createdAt: item.created_at,
505
- updatedAt: item.updated_at
506
- }
507
- })
508
- }
509
- }
510
-
511
- function buildCashoutItem(result: CashoutResponse): CashoutRequest {
512
- return {
513
- secureCode: result.secure_code,
514
- pcode: result.pcode,
515
- status: result.status as any,
516
- address: result.address,
517
- usdAmount: result.usd_amount,
518
- btcAmount: result.btc_amount,
519
- btcWholeUnitPrice: result.btc_whole_unit_price,
520
- expiration: result.expiration,
521
- atmId: result.atm_id,
522
- locDescription: result.loc_description,
523
- locLat: result.loc_lat,
524
- locLon: result.loc_lon
525
- }
526
- }
package/src/crypto.ts DELETED
@@ -1,144 +0,0 @@
1
- import { ethers, TransactionResponse } from 'ethers'
2
- import { SimpleMultisigTransactionData } from './models/SimpleMultisigTransactionData'
3
- import { ERC20_ABI } from './erc20Abi'
4
-
5
- export type TransactionRequest = ethers.TransactionRequest
6
-
7
- export function getPublicAddress(privateKey: string) {
8
- return new ethers.Wallet(privateKey).address
9
- }
10
-
11
- export async function sendNative(
12
- privateKey: string,
13
- tx: TransactionRequest,
14
- rpcUrl?: string
15
- ): Promise<TransactionResponse> {
16
- let txReq = { ...tx }
17
- const provider = rpcUrl ? new ethers.JsonRpcProvider(rpcUrl) : null
18
- const wallet = new ethers.Wallet(privateKey, provider)
19
- return wallet.sendTransaction(txReq)
20
- }
21
-
22
- export async function sendERC20(
23
- privateKey: string,
24
- tx: TransactionRequest & { tokenAddress: string },
25
- rpcUrl?: string
26
- ): Promise<TransactionResponse> {
27
- if (!tx.to) throw new Error('Missing to')
28
- if (tx.value == null) throw new Error('Missing value')
29
-
30
- const provider = rpcUrl ? new ethers.JsonRpcProvider(rpcUrl) : null
31
- const wallet = new ethers.Wallet(privateKey, provider)
32
-
33
- const token = new ethers.Contract(tx.tokenAddress, ERC20_ABI, wallet)
34
- return token.transfer(tx.to, tx.value)
35
- }
36
-
37
- export async function signNativeTransfer({
38
- toAddress,
39
- amount,
40
- privateKey,
41
- rpcUrl
42
- }: {
43
- toAddress: string
44
- amount: bigint
45
- privateKey: string
46
- rpcUrl: string
47
- }): Promise<string> {
48
- const provider = new ethers.JsonRpcProvider(rpcUrl)
49
-
50
- const network = await provider.getNetwork()
51
- const wallet = new ethers.Wallet(privateKey)
52
- const nonce = await provider.getTransactionCount(await wallet.getAddress())
53
-
54
- const tx = {
55
- to: toAddress,
56
- value: amount,
57
- chainId: network.chainId,
58
- nonce: nonce,
59
- gasLimit: 21000n,
60
- maxFeePerGas: ethers.parseUnits('50', 'gwei'),
61
- maxPriorityFeePerGas: ethers.parseUnits('2', 'gwei')
62
- }
63
-
64
- const signedTx = await wallet.signTransaction(tx)
65
- return signedTx
66
- }
67
-
68
- export async function signERC20Transfer({
69
- tokenAddress,
70
- toAddress,
71
- amount,
72
- privateKey,
73
- rpcUrl
74
- }: {
75
- tokenAddress: string
76
- toAddress: string
77
- amount: bigint
78
- privateKey: string
79
- rpcUrl: string
80
- }): Promise<string> {
81
- const provider = new ethers.JsonRpcProvider(rpcUrl)
82
-
83
- const network = await provider.getNetwork()
84
- const wallet = new ethers.Wallet(privateKey)
85
- const nonce = await provider.getTransactionCount(await wallet.getAddress())
86
-
87
- const erc20Interface = new ethers.Interface(ERC20_ABI)
88
- const data = erc20Interface.encodeFunctionData('transfer', [
89
- toAddress,
90
- amount
91
- ])
92
-
93
- const tx = {
94
- to: tokenAddress,
95
- value: 0n,
96
- data: data,
97
- chainId: network.chainId,
98
- nonce: nonce,
99
- gasLimit: 65000n,
100
- maxFeePerGas: ethers.parseUnits('50', 'gwei'),
101
- maxPriorityFeePerGas: ethers.parseUnits('2', 'gwei')
102
- }
103
-
104
- const signedTx = await wallet.signTransaction(tx)
105
- return signedTx
106
- }
107
-
108
- export async function signTypedData(
109
- privateKey: string,
110
- txData: SimpleMultisigTransactionData,
111
- rpcUrl?: string
112
- ): Promise<string> {
113
- const provider = rpcUrl ? new ethers.JsonRpcProvider(rpcUrl) : null
114
- const wallet = new ethers.Wallet(privateKey, provider)
115
-
116
- const signature = await wallet.signTypedData(
117
- txData.domain,
118
- { MultiSigTransaction: txData.types.MultiSigTransaction },
119
- {
120
- ...txData.message,
121
- value:
122
- txData.message.value === '0x'
123
- ? BigInt(0)
124
- : BigInt(txData.message.value),
125
- nonce: parseInt(txData.message.nonce as any)
126
- }
127
- )
128
-
129
- return signature
130
- }
131
-
132
- export async function sha256(message: string) {
133
- const encoder = new TextEncoder()
134
- const data = encoder.encode(message)
135
-
136
- const hashBuffer = await crypto.subtle.digest('SHA-256', data)
137
-
138
- const hashArray = Array.from(new Uint8Array(hashBuffer))
139
- const hashHex = hashArray
140
- .map((b) => b.toString(16).padStart(2, '0'))
141
- .join('')
142
-
143
- return hashHex
144
- }
@@ -1,38 +0,0 @@
1
- import DeviceInfo from 'react-native-device-info'
2
-
3
- export type Platform = 'web' | 'react-native' | 'unknown'
4
-
5
- function detectPlatform(): Platform {
6
- if (typeof window !== 'undefined' && typeof document !== 'undefined') {
7
- return 'web'
8
- }
9
- if (
10
- typeof navigator !== 'undefined' &&
11
- navigator.product === 'ReactNative'
12
- ) {
13
- return 'react-native'
14
- }
15
-
16
- return 'unknown'
17
- }
18
-
19
- export async function getUserAgent() {
20
- return DeviceInfo.getUserAgent()
21
- }
22
-
23
- export async function getDeviceId(): Promise<string> {
24
- return DeviceInfo.getUniqueId()
25
- }
26
-
27
- export async function getBundleId() {
28
- const platform = detectPlatform()
29
-
30
- switch (platform) {
31
- case 'web':
32
- return location.origin
33
- case 'react-native':
34
- return DeviceInfo.getBundleId()
35
- default:
36
- return 'Unknown'
37
- }
38
- }