@ardrive/turbo-sdk 1.4.1 → 1.5.0-alpha.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.
Files changed (46) hide show
  1. package/README.md +33 -72
  2. package/bundles/web.bundle.min.js +4116 -348
  3. package/lib/cjs/common/index.js +1 -0
  4. package/lib/cjs/common/payment.js +104 -3
  5. package/lib/cjs/common/signer.js +45 -0
  6. package/lib/cjs/common/token.js +132 -0
  7. package/lib/cjs/common/turbo.js +13 -0
  8. package/lib/cjs/node/factory.js +2 -1
  9. package/lib/cjs/node/signer.js +4 -17
  10. package/lib/cjs/types.js +2 -0
  11. package/lib/cjs/version.js +1 -1
  12. package/lib/cjs/web/factory.js +3 -1
  13. package/lib/cjs/web/signer.js +22 -26
  14. package/lib/esm/common/index.js +1 -0
  15. package/lib/esm/common/payment.js +104 -3
  16. package/lib/esm/common/signer.js +41 -0
  17. package/lib/esm/common/token.js +123 -0
  18. package/lib/esm/common/turbo.js +13 -0
  19. package/lib/esm/node/factory.js +2 -1
  20. package/lib/esm/node/signer.js +5 -18
  21. package/lib/esm/types.js +1 -1
  22. package/lib/esm/version.js +1 -1
  23. package/lib/esm/web/factory.js +3 -1
  24. package/lib/esm/web/signer.js +22 -26
  25. package/lib/types/common/index.d.ts +1 -0
  26. package/lib/types/common/index.d.ts.map +1 -1
  27. package/lib/types/common/payment.d.ts +10 -19
  28. package/lib/types/common/payment.d.ts.map +1 -1
  29. package/lib/types/common/signer.d.ts +16 -0
  30. package/lib/types/common/signer.d.ts.map +1 -0
  31. package/lib/types/common/token.d.ts +56 -0
  32. package/lib/types/common/token.d.ts.map +1 -0
  33. package/lib/types/common/turbo.d.ts +12 -1
  34. package/lib/types/common/turbo.d.ts.map +1 -1
  35. package/lib/types/node/factory.d.ts +1 -1
  36. package/lib/types/node/factory.d.ts.map +1 -1
  37. package/lib/types/node/signer.d.ts +4 -15
  38. package/lib/types/node/signer.d.ts.map +1 -1
  39. package/lib/types/types.d.ts +108 -5
  40. package/lib/types/types.d.ts.map +1 -1
  41. package/lib/types/version.d.ts +1 -1
  42. package/lib/types/web/factory.d.ts +1 -1
  43. package/lib/types/web/factory.d.ts.map +1 -1
  44. package/lib/types/web/signer.d.ts +8 -15
  45. package/lib/types/web/signer.d.ts.map +1 -1
  46. package/package.json +10 -5
package/README.md CHANGED
@@ -119,7 +119,7 @@ const rates = await turbo.getFiatRates();
119
119
  ESM:
120
120
 
121
121
  ```javascript
122
- import { TurboFactory } from '@ardrive/turbo-sdk/web';
122
+ import { TurboFactory } from '@ardrive/turbo-sdk/<node/web>';
123
123
 
124
124
  const turbo = TurboFactory.unauthenticated();
125
125
  const rates = await turbo.getFiatRates();
@@ -140,85 +140,18 @@ const rates = await turbo.getFiatRates();
140
140
 
141
141
  #### CommonJS
142
142
 
143
- Project's `package.json`:
144
-
145
- ```json
146
- {
147
- "type": "commonjs" // or absent
148
- }
149
- ```
150
-
151
- Project's `tsconfig.json`:
152
-
153
- ```json
154
- {
155
- "compilerOptions": {
156
- "module": "CommonJS",
157
- "moduleResolution": "Node",
158
- "skipLibCheck": true
159
- }
160
- }
161
- ```
162
-
163
- Usage (Node & Web):
164
-
165
- ```javascript
166
- const { TurboFactory } = require('@ardrive/turbo-sdk');
167
-
168
- const turbo = TurboFactory.unauthenticated();
169
- const rates = await turbo.getFiatRates();
170
- ```
143
+ Example available in the [examples/typescript/cjs].
171
144
 
172
145
  #### ESM
173
146
 
174
- Project's `package.json`:
175
-
176
- ```json
177
- {
178
- "type": "module"
179
- }
180
- ```
181
-
182
- Project's `tsconfig.json`:
183
-
184
- ```json
185
- {
186
- "compilerOptions": {
187
- "module": "NodeNext",
188
- "moduleResolution": "NodeNext",
189
- "skipLibCheck": true
190
- }
191
- }
192
- ```
193
-
194
- #### Usage
195
-
196
- Node:
197
-
198
- ```javascript
199
- import { TurboFactory } from '@ardrive/turbo-sdk/node';
200
-
201
- const turbo = TurboFactory.unauthenticated();
202
- const rates = await turbo.getFiatRates();
203
- ```
204
-
205
- Web:
206
-
207
- ```javascript
208
- import { TurboFactory } from '@ardrive/turbo-sdk/web';
209
-
210
- const turbo = TurboFactory.unauthenticated();
211
- const rates = await turbo.getFiatRates();
212
- ```
147
+ Example available in the [examples/typescript/esm].
213
148
 
214
149
  ### Typescript
215
150
 
216
151
  The SDK provides TypeScript types. When you import the SDK in a TypeScript project:
217
152
 
218
153
  ```typescript
219
- import { TurboFactory } from '@ardrive/turbo-sdk/web';
220
-
221
- // or '@ardrive/turbo-sdk/node' for Node.js projects
154
+ import { TurboFactory } from '@ardrive/turbo-sdk/<node/web>';
222
155
  ```
223
156
 
224
157
  Types are exported from `./lib/types/[node/web]/index.d.ts` and should be automatically recognized, offering benefits such as type-checking and autocompletion.
@@ -325,6 +258,17 @@ Types are exported from `./lib/types/[node/web]/index.d.ts` and should be automa
325
258
  }
326
259
  ```
327
260
 
261
+ - `submitFundTransaction({ txId })` - Submits the transaction ID of a funding transaction to Turbo Payment Service for top up processing. The `txId` is the transaction ID of the transaction to be submitted.
262
+
263
+ - Note: Use this API if you've already executed your token transfer to the Turbo wallet. Otherwise, consider using `topUpWithTokens` to execute a new token transfer to the Turbo wallet and submit its resulting transaction ID for top up processing all in one go
264
+
265
+ ```typescript
266
+ const turbo = TurboFactory.unauthenticated(); // defaults to arweave token type
267
+ const { status, id, ...fundResult } = await turbo.submitFundTransaction({
268
+ txId: 'my-valid-arweave-fund-transaction-id',
269
+ });
270
+ ```
271
+
328
272
  ### TurboAuthenticatedClient
329
273
 
330
274
  - `getBalance()` - Issues a signed request to get the credit balance of a wallet measured in AR (measured in Winston Credits, or winc).
@@ -391,6 +335,20 @@ Types are exported from `./lib/types/[node/web]/index.d.ts` and should be automa
391
335
  });
392
336
  ```
393
337
 
338
+ - `topUpWithTokens({ tokenAmount, feeMultiplier })` - Tops up the connected wallet with Credits by submitting a payment transaction for the token amount to the Turbo wallet and then submitting that transaction id to Turbo Payment Service for top up processing.
339
+
340
+ - The `tokenAmount` is the amount of tokens in the token type's smallest unit value (e.g: Winston for arweave token type) to fund the wallet with.
341
+ - The `feeMultiplier` (optional) is the multiplier to apply to the reward for the transaction to modify its chances of being mined. Credits will be added to the wallet balance after the transaction is confirmed on the given blockchain. Defaults to 1.0, meaning no multiplier.
342
+
343
+ ```typescript
344
+ const turbo = TurboFactory.authenticated({ signer, token: 'arweave' });
345
+
346
+ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
347
+ tokenAmount: WinstonToTokenAmount(100_000_000), // 0.0001 AR
348
+ feeMultiplier: 1.1, // 10% increase in reward for improved mining chances
349
+ });
350
+ ```
351
+
394
352
  ## Developers
395
353
 
396
354
  ### Requirements
@@ -406,7 +364,8 @@ Types are exported from `./lib/types/[node/web]/index.d.ts` and should be automa
406
364
 
407
365
  ### Testing
408
366
 
409
- - `yarn test` - runs integration tests
367
+ - `yarn test` - runs integration tests against dev environment (e.g. `https://payment.ardrive.dev` and `https://upload.ardrive.dev`)
368
+ - `yarn test:docker` - runs integration tests against locally running docker containers (recommended)
410
369
  - `yarn example:web` - opens up the example web page
411
370
  - `yarn example:cjs` - runs example CJS node script
412
371
  - `yarn example:esm` - runs example ESM node script
@@ -429,6 +388,8 @@ For more information on how to contribute, please see [CONTRIBUTING.md].
429
388
 
430
389
  [package.json]: ./package.json
431
390
  [examples]: ./examples
391
+ [examples/typescript/cjs]: ./examples/typescript/cjs
392
+ [examples/typescript/esm]: ./examples/typescript/esm
432
393
  [TurboAuthenticatedClient]: #turboauthenticatedclient
433
394
  [AbortSignal]: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
434
395
  [CONTRIBUTING.md]: ./CONTRIBUTING.md