@alephium/web3 0.1.0 → 0.2.0-rc.10

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 (93) hide show
  1. package/.eslintignore +2 -2
  2. package/README.md +2 -135
  3. package/contracts/greeter/greeter.ral +7 -0
  4. package/contracts/{greeter_interface.ral → greeter/greeter_interface.ral} +1 -0
  5. package/contracts/greeter_main.ral +2 -4
  6. package/dist/alephium-web3.min.js +1 -1
  7. package/dist/alephium-web3.min.js.LICENSE.txt +0 -17
  8. package/dist/alephium-web3.min.js.map +1 -1
  9. package/dist/scripts/create-project.js +3 -2
  10. package/dist/src/api/api-alephium.d.ts +58 -13
  11. package/dist/src/api/api-alephium.js +19 -3
  12. package/dist/src/api/api-explorer.d.ts +32 -16
  13. package/dist/src/api/api-explorer.js +26 -0
  14. package/dist/src/api/index.d.ts +2 -2
  15. package/dist/src/api/index.js +18 -3
  16. package/dist/src/contract/contract.d.ts +105 -48
  17. package/dist/src/contract/contract.js +362 -189
  18. package/dist/src/contract/events.d.ts +7 -25
  19. package/dist/src/contract/events.js +18 -31
  20. package/dist/src/contract/index.js +5 -1
  21. package/dist/src/global.d.ts +4 -0
  22. package/dist/src/global.js +38 -0
  23. package/dist/src/index.d.ts +3 -0
  24. package/dist/src/index.js +21 -1
  25. package/dist/src/signer/index.d.ts +0 -1
  26. package/dist/src/signer/index.js +5 -2
  27. package/dist/src/signer/signer.d.ts +1 -1
  28. package/dist/src/signer/signer.js +8 -3
  29. package/dist/src/transaction/index.d.ts +1 -0
  30. package/dist/src/{test → transaction}/index.js +6 -13
  31. package/dist/src/transaction/status.d.ts +10 -0
  32. package/dist/src/transaction/status.js +48 -0
  33. package/dist/src/utils/index.d.ts +1 -2
  34. package/dist/src/utils/index.js +6 -3
  35. package/dist/src/utils/subscription.d.ts +23 -0
  36. package/dist/src/utils/subscription.js +53 -0
  37. package/dist/src/utils/utils.d.ts +5 -2
  38. package/dist/src/utils/utils.js +25 -16
  39. package/jest-config.json +11 -0
  40. package/package.json +7 -35
  41. package/scripts/create-project.ts +3 -2
  42. package/src/api/api-alephium.ts +73 -8
  43. package/src/api/api-explorer.ts +30 -0
  44. package/src/api/index.ts +13 -3
  45. package/src/contract/contract.ts +512 -279
  46. package/src/contract/events.ts +21 -48
  47. package/src/{utils/transaction.ts → global.ts} +14 -15
  48. package/src/index.ts +4 -0
  49. package/src/signer/index.ts +0 -1
  50. package/src/signer/signer.ts +4 -3
  51. package/src/{utils/password-crypto.test.ts → transaction/index.ts} +1 -9
  52. package/src/transaction/status.ts +58 -0
  53. package/src/utils/index.ts +1 -2
  54. package/src/utils/subscription.ts +72 -0
  55. package/src/utils/utils.ts +16 -8
  56. package/templates/base/package.json +2 -2
  57. package/templates/base/src/greeter.ts +8 -7
  58. package/templates/react/package.json +2 -2
  59. package/templates/react/src/App.tsx +2 -2
  60. package/.eslintrc.json +0 -21
  61. package/LICENSE +0 -165
  62. package/contracts/add.ral +0 -16
  63. package/contracts/greeter.ral +0 -7
  64. package/contracts/main.ral +0 -6
  65. package/contracts/sub.ral +0 -9
  66. package/dist/src/signer/node-wallet.d.ts +0 -13
  67. package/dist/src/signer/node-wallet.js +0 -60
  68. package/dist/src/test/index.d.ts +0 -7
  69. package/dist/src/test/privatekey-wallet.d.ts +0 -12
  70. package/dist/src/test/privatekey-wallet.js +0 -68
  71. package/dist/src/utils/password-crypto.d.ts +0 -2
  72. package/dist/src/utils/password-crypto.js +0 -69
  73. package/dist/src/utils/transaction.d.ts +0 -2
  74. package/dist/src/utils/transaction.js +0 -58
  75. package/gitignore +0 -10
  76. package/src/contract/ralph.test.ts +0 -178
  77. package/src/fixtures/address.json +0 -36
  78. package/src/fixtures/balance.json +0 -9
  79. package/src/fixtures/self-clique.json +0 -19
  80. package/src/fixtures/transaction.json +0 -13
  81. package/src/fixtures/transactions.json +0 -179
  82. package/src/signer/fixtures/genesis.json +0 -26
  83. package/src/signer/fixtures/wallets.json +0 -26
  84. package/src/signer/node-wallet.ts +0 -74
  85. package/src/test/index.ts +0 -32
  86. package/src/test/privatekey-wallet.ts +0 -58
  87. package/src/utils/address.test.ts +0 -47
  88. package/src/utils/djb2.test.ts +0 -35
  89. package/src/utils/password-crypto.ts +0 -77
  90. package/src/utils/transaction.test.ts +0 -50
  91. package/src/utils/utils.test.ts +0 -160
  92. package/test/contract.test.ts +0 -161
  93. package/test/events.test.ts +0 -139
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-rc.10",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -27,29 +27,16 @@
27
27
  },
28
28
  "author": "Alephium dev <dev@alephium.org>",
29
29
  "config": {
30
- "alephium_version": "1.4.2",
31
- "explorer_backend_version": "1.7.0"
30
+ "alephium_version": "1.5.0-rc7",
31
+ "explorer_backend_version": "1.7.1"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "rm -rf dist/* && npx tsc --build . && webpack",
35
- "bundle": "webpack",
35
+ "test": "jest -i --config ./jest-config.json",
36
36
  "update-schemas": "npm run update-schema:alephium && npm run update-schema:explorer",
37
37
  "update-schema:alephium": "npx swagger-typescript-api -t ./configs -o ./src/api -n api-alephium.ts -p https://raw.githubusercontent.com/alephium/alephium/v${npm_package_config_alephium_version}/api/src/main/resources/openapi.json",
38
38
  "update-schema:explorer": "npx swagger-typescript-api -t ./configs -o ./src/api -n api-explorer.ts -p https://raw.githubusercontent.com/alephium/explorer-backend/v${npm_package_config_explorer_backend_version}/app/src/main/resources/explorer-backend-openapi.json",
39
39
  "check-versions": "node scripts/check-versions.js ${npm_package_config_alephium_version} ${npm_package_config_explorer_backend_version}",
40
- "dev": "tsnd --respawn lib/index.ts",
41
- "lint": "eslint . --ext ts",
42
- "lint:fix": "eslint . --fix --ext ts",
43
- "test": "jest -i --config ./configs/jest.config.ts",
44
- "test:client": "jest -i --config ./configs/jest-client.config.ts",
45
- "test:unit": "jest -i --config ./configs/jest-unit.config.ts",
46
- "test:watch": "npm run test -- --watch --coverage=false",
47
- "test:watch:unit": "npm run test:unit -- --watch --coverage=false",
48
- "test:watch:client": "npm run test:client -- --watch --coverage=false",
49
- "prepublishOnly": "npm run build",
50
- "prepack": "node scripts/rename-gitignore.js .gitignore gitignore",
51
- "postpack": "node scripts/rename-gitignore.js gitignore .gitignore",
52
- "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
53
40
  "start-devnet": "node scripts/start-devnet.js ${npm_package_config_alephium_version}",
54
41
  "restart-devnet": "npm run start-devnet",
55
42
  "stop-devnet": "node scripts/stop-devnet.js"
@@ -64,15 +51,12 @@
64
51
  "buffer": "^6.0.3",
65
52
  "commander": "^9.1.0",
66
53
  "cross-fetch": "^3.1.5",
67
- "crypto-js": "4.1.1",
68
- "elliptic": "6.5.4",
69
54
  "eventemitter3": "^4.0.7",
70
55
  "find-up": "^2.1.0",
71
56
  "fs-extra": "^10.0.1"
72
57
  },
73
58
  "devDependencies": {
74
- "@types/crypto-js": "^4.1.1",
75
- "@types/elliptic": "^6.4.13",
59
+ "@babel/eslint-parser": "^7.18.9",
76
60
  "@types/find-up": "^2.1.0",
77
61
  "@types/fs-extra": "^9.0.13",
78
62
  "@types/jest": "^27.5.1",
@@ -81,14 +65,12 @@
81
65
  "@types/rewire": "^2.5.28",
82
66
  "@typescript-eslint/eslint-plugin": "^4.30.0",
83
67
  "@typescript-eslint/parser": "^4.30.0",
84
- "babel-eslint": "^10.1.0",
85
68
  "clean-webpack-plugin": "4.0.0",
86
69
  "crypto-browserify": "^3.12.0",
87
70
  "eslint": "^7.32.0",
88
71
  "eslint-config-prettier": "^8.5.0",
89
72
  "eslint-plugin-header": "^3.1.1",
90
73
  "eslint-plugin-prettier": "^4.0.0",
91
- "eslint-plugin-react": "^7.29.4",
92
74
  "eslint-plugin-security": "1.4.0",
93
75
  "html-webpack-plugin": "5.5.0",
94
76
  "jest": "^28.1.0",
@@ -98,7 +80,6 @@
98
80
  "mock-socket": "^9.0.8",
99
81
  "prettier": "^2.3.2",
100
82
  "process": "^0.11.10",
101
- "react-app-rewired": "^2.2.1",
102
83
  "rewire": "^6.0.0",
103
84
  "shelljs": "^0.8.5",
104
85
  "stream-browserify": "^3.0.0",
@@ -107,21 +88,12 @@
107
88
  "ts-jest": "^28.0.2",
108
89
  "ts-node": "^10.7.0",
109
90
  "tslib": "^2.3.1",
110
- "typescript": "^4.4.2",
91
+ "typescript": "4.7.4",
111
92
  "webpack": "^5.72.0",
112
93
  "webpack-cli": "^4.9.2"
113
94
  },
114
95
  "engines": {
115
- "node": ">=14.0.0",
96
+ "node": ">=16.0.0",
116
97
  "npm": ">=7.0.0"
117
- },
118
- "prettier": {
119
- "printWidth": 120,
120
- "tabWidth": 2,
121
- "useTabs": false,
122
- "semi": false,
123
- "singleQuote": true,
124
- "bracketSameLine": false,
125
- "trailingComma": "none"
126
98
  }
127
99
  }
@@ -73,7 +73,7 @@ function prepareShared(packageRoot: string, projectRoot: string) {
73
73
  console.log('...')
74
74
 
75
75
  fsExtra.copySync(path.join(packageRoot, 'templates/shared'), projectRoot)
76
- copy('', ['.editorconfig', '.eslintignore', '.gitattributes', 'LICENSE'])
76
+ copy('', ['.editorconfig', '.eslintignore', '.gitattributes'])
77
77
  copy('dev', ['user.conf'])
78
78
  copy('scripts', ['start-devnet.js', 'stop-devnet.js'])
79
79
  if (fsExtra.existsSync(path.join(packageRoot, 'gitignore'))) {
@@ -87,7 +87,8 @@ function prepareShared(packageRoot: string, projectRoot: string) {
87
87
 
88
88
  function prepareBase(packageRoot: string, projectRoot: string) {
89
89
  prepareShared(packageRoot, projectRoot)
90
- copy('contracts', ['greeter.ral', 'greeter_interface.ral', 'greeter_main.ral'])
90
+ copy('contracts', ['greeter_main.ral'])
91
+ copy('contracts/greeter', ['greeter.ral', 'greeter_interface.ral'])
91
92
  fsExtra.copySync(path.join(packageRoot, 'templates/base'), projectRoot)
92
93
  }
93
94
 
@@ -96,6 +96,8 @@ export interface Balance {
96
96
 
97
97
  /** @format x.x ALPH */
98
98
  lockedBalanceHint: string
99
+ tokenBalances?: Token[]
100
+ lockedTokenBalances?: Token[]
99
101
 
100
102
  /** @format int32 */
101
103
  utxoNum: number
@@ -205,6 +207,9 @@ export interface BuildDeployContractTx {
205
207
 
206
208
  /** @format uint256 */
207
209
  gasPrice?: string
210
+
211
+ /** @format block-hash */
212
+ targetBlockHash?: string
208
213
  }
209
214
 
210
215
  export interface BuildDeployContractTxResult {
@@ -244,6 +249,9 @@ export interface BuildExecuteScriptTx {
244
249
 
245
250
  /** @format uint256 */
246
251
  gasPrice?: string
252
+
253
+ /** @format block-hash */
254
+ targetBlockHash?: string
247
255
  }
248
256
 
249
257
  export interface BuildExecuteScriptTxResult {
@@ -309,6 +317,9 @@ export interface BuildSweepAddressTransactions {
309
317
 
310
318
  /** @format uint256 */
311
319
  gasPrice?: string
320
+
321
+ /** @format block-hash */
322
+ targetBlockHash?: string
312
323
  }
313
324
 
314
325
  export interface BuildSweepAddressTransactionsResult {
@@ -332,6 +343,9 @@ export interface BuildTransaction {
332
343
 
333
344
  /** @format uint256 */
334
345
  gasPrice?: string
346
+
347
+ /** @format block-hash */
348
+ targetBlockHash?: string
335
349
  }
336
350
 
337
351
  export interface BuildTransactionResult {
@@ -408,6 +422,7 @@ export interface ChangeActiveAddress {
408
422
  }
409
423
 
410
424
  export interface CompileContractResult {
425
+ name: string
411
426
  bytecode: string
412
427
 
413
428
  /** @format 32-byte-hash */
@@ -415,12 +430,29 @@ export interface CompileContractResult {
415
430
  fields: FieldsSig
416
431
  functions: FunctionSig[]
417
432
  events: EventSig[]
433
+ warnings: string[]
434
+ }
435
+
436
+ export interface CompileProjectResult {
437
+ contracts: CompileContractResult[]
438
+ scripts: CompileScriptResult[]
418
439
  }
419
440
 
420
441
  export interface CompileScriptResult {
442
+ name: string
421
443
  bytecodeTemplate: string
422
444
  fields: FieldsSig
423
445
  functions: FunctionSig[]
446
+ warnings: string[]
447
+ }
448
+
449
+ export interface CompilerOptions {
450
+ ignoreUnusedConstantsWarnings?: boolean
451
+ ignoreUnusedVariablesWarnings?: boolean
452
+ ignoreUnusedFieldsWarnings?: boolean
453
+ ignoreUnusedPrivateFunctionsWarnings?: boolean
454
+ ignoreReadonlyCheckWarnings?: boolean
455
+ ignoreExternalCallCheckWarnings?: boolean
424
456
  }
425
457
 
426
458
  export interface Confirmed {
@@ -443,6 +475,7 @@ export interface Confirmed {
443
475
 
444
476
  export interface Contract {
445
477
  code: string
478
+ compilerOptions?: CompilerOptions
446
479
  }
447
480
 
448
481
  export interface ContractEvent {
@@ -547,7 +580,6 @@ export type DiscoveryAction = Reachable | Unreachable
547
580
 
548
581
  export interface EventSig {
549
582
  name: string
550
- signature: string
551
583
  fieldNames: string[]
552
584
  fieldTypes: string[]
553
585
  }
@@ -557,9 +589,9 @@ export interface FetchResponse {
557
589
  }
558
590
 
559
591
  export interface FieldsSig {
560
- signature: string
561
592
  names: string[]
562
593
  types: string[]
594
+ isMutable: boolean[]
563
595
  }
564
596
 
565
597
  export interface FixedAssetOutput {
@@ -585,9 +617,12 @@ export interface FixedAssetOutput {
585
617
 
586
618
  export interface FunctionSig {
587
619
  name: string
588
- signature: string
589
- argNames: string[]
590
- argTypes: string[]
620
+ usePreapprovedAssets: boolean
621
+ useAssetsInContract: boolean
622
+ isPublic: boolean
623
+ paramNames: string[]
624
+ paramTypes: string[]
625
+ paramIsMutable: boolean[]
591
626
  returnTypes: string[]
592
627
  }
593
628
 
@@ -689,6 +724,11 @@ export interface Penalty {
689
724
  type: string
690
725
  }
691
726
 
727
+ export interface Project {
728
+ code: string
729
+ compilerOptions?: CompilerOptions
730
+ }
731
+
692
732
  export interface Reachable {
693
733
  peers: string[]
694
734
  type: string
@@ -715,6 +755,7 @@ export interface RevealMnemonicResult {
715
755
 
716
756
  export interface Script {
717
757
  code: string
758
+ compilerOptions?: CompilerOptions
718
759
  }
719
760
 
720
761
  export interface SelfClique {
@@ -776,6 +817,9 @@ export interface Sweep {
776
817
 
777
818
  /** @format int32 */
778
819
  utxosLimit?: number
820
+
821
+ /** @format block-hash */
822
+ targetBlockHash?: string
779
823
  }
780
824
 
781
825
  export interface SweepAddressTransaction {
@@ -1097,7 +1141,7 @@ export enum ContentType {
1097
1141
  }
1098
1142
 
1099
1143
  export class HttpClient<SecurityDataType = unknown> {
1100
- public baseUrl: string = '{protocol}://{host}:{port}'
1144
+ public baseUrl: string = '../'
1101
1145
  private securityData: SecurityDataType | null = null
1102
1146
  private securityWorker?: ApiConfig<SecurityDataType>['securityWorker']
1103
1147
  private abortControllers = new Map<CancelToken, AbortController>()
@@ -1262,8 +1306,8 @@ export class HttpClient<SecurityDataType = unknown> {
1262
1306
 
1263
1307
  /**
1264
1308
  * @title Alephium API
1265
- * @version 1.4.2
1266
- * @baseUrl {protocol}://{host}:{port}
1309
+ * @version 1.5.0
1310
+ * @baseUrl ../
1267
1311
  */
1268
1312
  export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
1269
1313
  wallets = {
@@ -2143,6 +2187,27 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2143
2187
  ...params
2144
2188
  }).then(convertHttpResponse),
2145
2189
 
2190
+ /**
2191
+ * No description
2192
+ *
2193
+ * @tags Contracts
2194
+ * @name PostContractsCompileProject
2195
+ * @summary Compile a project
2196
+ * @request POST:/contracts/compile-project
2197
+ */
2198
+ postContractsCompileProject: (data: Project, params: RequestParams = {}) =>
2199
+ this.request<
2200
+ CompileProjectResult,
2201
+ BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
2202
+ >({
2203
+ path: `/contracts/compile-project`,
2204
+ method: 'POST',
2205
+ body: data,
2206
+ type: ContentType.Json,
2207
+ format: 'json',
2208
+ ...params
2209
+ }).then(convertHttpResponse),
2210
+
2146
2211
  /**
2147
2212
  * No description
2148
2213
  *
@@ -847,6 +847,36 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
847
847
  path: `/utils/sanity-check`,
848
848
  method: 'PUT',
849
849
  ...params
850
+ }).then(convertHttpResponse),
851
+
852
+ /**
853
+ * @description Update global log level, accepted: TRACE, DEBUG, INFO, WARN, ERROR
854
+ *
855
+ * @tags Utils
856
+ * @name PutUtilsUpdateGlobalLoglevel
857
+ * @request PUT:/utils/update-global-loglevel
858
+ */
859
+ putUtilsUpdateGlobalLoglevel: (data: 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR', params: RequestParams = {}) =>
860
+ this.request<void, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
861
+ path: `/utils/update-global-loglevel`,
862
+ method: 'PUT',
863
+ body: data,
864
+ ...params
865
+ }).then(convertHttpResponse),
866
+
867
+ /**
868
+ * @description Update logging file, only logback.xml is accepted
869
+ *
870
+ * @tags Utils
871
+ * @name PutUtilsUpdateLogConfig
872
+ * @request PUT:/utils/update-log-config
873
+ */
874
+ putUtilsUpdateLogConfig: (data: string, params: RequestParams = {}) =>
875
+ this.request<void, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
876
+ path: `/utils/update-log-config`,
877
+ method: 'PUT',
878
+ body: data,
879
+ ...params
850
880
  }).then(convertHttpResponse)
851
881
  }
852
882
  }
package/src/api/index.ts CHANGED
@@ -19,9 +19,19 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
19
19
  import { Api as NodeApi } from './api-alephium'
20
20
  import { Api as ExplorerApi } from './api-explorer'
21
21
 
22
- export class NodeProvider extends NodeApi<null> {
23
- constructor(baseUrl: string) {
24
- super({ baseUrl: baseUrl })
22
+ export class NodeProvider extends NodeApi<string> {
23
+ constructor(baseUrl: string, apiKey?: string) {
24
+ // eslint-disable-next-line security/detect-possible-timing-attacks
25
+ if (apiKey === undefined) {
26
+ super({ baseUrl: baseUrl })
27
+ } else {
28
+ super({
29
+ baseUrl: baseUrl,
30
+ baseApiParams: { secure: true },
31
+ securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
32
+ })
33
+ this.setSecurityData(apiKey)
34
+ }
25
35
  }
26
36
  }
27
37