@alephium/web3 0.0.1-test.0

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 (137) hide show
  1. package/.editorconfig +13 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.json +21 -0
  4. package/.gitattributes +1 -0
  5. package/LICENSE +165 -0
  6. package/README.md +136 -0
  7. package/contracts/add.ral +16 -0
  8. package/contracts/greeter.ral +7 -0
  9. package/contracts/greeter_interface.ral +3 -0
  10. package/contracts/greeter_main.ral +9 -0
  11. package/contracts/main.ral +6 -0
  12. package/contracts/sub.ral +9 -0
  13. package/dev/user.conf +29 -0
  14. package/dist/alephium-web3.min.js +3 -0
  15. package/dist/alephium-web3.min.js.LICENSE.txt +27 -0
  16. package/dist/alephium-web3.min.js.map +1 -0
  17. package/dist/scripts/check-versions.d.ts +1 -0
  18. package/dist/scripts/check-versions.js +39 -0
  19. package/dist/scripts/create-project.d.ts +2 -0
  20. package/dist/scripts/create-project.js +124 -0
  21. package/dist/scripts/header.d.ts +0 -0
  22. package/dist/scripts/header.js +18 -0
  23. package/dist/scripts/rename-gitignore.d.ts +1 -0
  24. package/dist/scripts/rename-gitignore.js +24 -0
  25. package/dist/scripts/start-devnet.d.ts +1 -0
  26. package/dist/scripts/start-devnet.js +131 -0
  27. package/dist/scripts/stop-devnet.d.ts +1 -0
  28. package/dist/scripts/stop-devnet.js +32 -0
  29. package/dist/src/api/api-alephium.d.ts +1473 -0
  30. package/dist/src/api/api-alephium.js +1143 -0
  31. package/dist/src/api/api-explorer.d.ts +475 -0
  32. package/dist/src/api/api-explorer.js +457 -0
  33. package/dist/src/api/index.d.ts +10 -0
  34. package/dist/src/api/index.js +55 -0
  35. package/dist/src/constants.d.ts +2 -0
  36. package/dist/src/constants.js +22 -0
  37. package/dist/src/contract/contract.d.ts +182 -0
  38. package/dist/src/contract/contract.js +760 -0
  39. package/dist/src/contract/events.d.ts +11 -0
  40. package/dist/src/contract/events.js +64 -0
  41. package/dist/src/contract/index.d.ts +3 -0
  42. package/dist/src/contract/index.js +32 -0
  43. package/dist/src/contract/ralph.d.ts +12 -0
  44. package/dist/src/contract/ralph.js +362 -0
  45. package/dist/src/index.d.ts +6 -0
  46. package/dist/src/index.js +35 -0
  47. package/dist/src/signer/index.d.ts +2 -0
  48. package/dist/src/signer/index.js +31 -0
  49. package/dist/src/signer/node-wallet.d.ts +13 -0
  50. package/dist/src/signer/node-wallet.js +60 -0
  51. package/dist/src/signer/signer.d.ts +143 -0
  52. package/dist/src/signer/signer.js +184 -0
  53. package/dist/src/test/index.d.ts +7 -0
  54. package/dist/src/test/index.js +41 -0
  55. package/dist/src/test/privatekey-wallet.d.ts +12 -0
  56. package/dist/src/test/privatekey-wallet.js +68 -0
  57. package/dist/src/transaction/index.d.ts +2 -0
  58. package/dist/src/transaction/index.js +31 -0
  59. package/dist/src/transaction/sign-verify.d.ts +2 -0
  60. package/dist/src/transaction/sign-verify.js +58 -0
  61. package/dist/src/transaction/status.d.ts +10 -0
  62. package/dist/src/transaction/status.js +48 -0
  63. package/dist/src/utils/address.d.ts +1 -0
  64. package/dist/src/utils/address.js +42 -0
  65. package/dist/src/utils/bs58.d.ts +4 -0
  66. package/dist/src/utils/bs58.js +28 -0
  67. package/dist/src/utils/djb2.d.ts +1 -0
  68. package/dist/src/utils/djb2.js +27 -0
  69. package/dist/src/utils/index.d.ts +6 -0
  70. package/dist/src/utils/index.js +35 -0
  71. package/dist/src/utils/password-crypto.d.ts +2 -0
  72. package/dist/src/utils/password-crypto.js +69 -0
  73. package/dist/src/utils/subscription.d.ts +24 -0
  74. package/dist/src/utils/subscription.js +52 -0
  75. package/dist/src/utils/utils.d.ts +30 -0
  76. package/dist/src/utils/utils.js +199 -0
  77. package/gitignore +10 -0
  78. package/package.json +127 -0
  79. package/scripts/check-versions.js +45 -0
  80. package/scripts/create-project.ts +136 -0
  81. package/scripts/header.js +17 -0
  82. package/scripts/rename-gitignore.js +24 -0
  83. package/scripts/start-devnet.js +141 -0
  84. package/scripts/stop-devnet.js +32 -0
  85. package/src/api/api-alephium.ts +2430 -0
  86. package/src/api/api-explorer.ts +852 -0
  87. package/src/api/index.ts +35 -0
  88. package/src/constants.ts +20 -0
  89. package/src/contract/contract.ts +1014 -0
  90. package/src/contract/events.ts +75 -0
  91. package/src/contract/index.ts +21 -0
  92. package/src/contract/ralph.test.ts +178 -0
  93. package/src/contract/ralph.ts +362 -0
  94. package/src/fixtures/address.json +36 -0
  95. package/src/fixtures/balance.json +9 -0
  96. package/src/fixtures/self-clique.json +19 -0
  97. package/src/fixtures/transaction.json +13 -0
  98. package/src/fixtures/transactions.json +179 -0
  99. package/src/index.ts +25 -0
  100. package/src/signer/fixtures/genesis.json +26 -0
  101. package/src/signer/fixtures/wallets.json +26 -0
  102. package/src/signer/index.ts +20 -0
  103. package/src/signer/node-wallet.ts +74 -0
  104. package/src/signer/signer.ts +313 -0
  105. package/src/test/index.ts +32 -0
  106. package/src/test/privatekey-wallet.ts +58 -0
  107. package/src/transaction/index.ts +20 -0
  108. package/src/transaction/sign-verify.test.ts +50 -0
  109. package/src/transaction/sign-verify.ts +39 -0
  110. package/src/transaction/status.ts +58 -0
  111. package/src/utils/address.test.ts +47 -0
  112. package/src/utils/address.ts +39 -0
  113. package/src/utils/bs58.ts +26 -0
  114. package/src/utils/djb2.test.ts +35 -0
  115. package/src/utils/djb2.ts +25 -0
  116. package/src/utils/index.ts +24 -0
  117. package/src/utils/password-crypto.test.ts +27 -0
  118. package/src/utils/password-crypto.ts +77 -0
  119. package/src/utils/subscription.ts +72 -0
  120. package/src/utils/utils.test.ts +160 -0
  121. package/src/utils/utils.ts +209 -0
  122. package/templates/base/README.md +34 -0
  123. package/templates/base/package.json +35 -0
  124. package/templates/base/src/greeter.ts +41 -0
  125. package/templates/base/tsconfig.json +19 -0
  126. package/templates/react/README.md +34 -0
  127. package/templates/react/config-overrides.js +18 -0
  128. package/templates/react/package.json +66 -0
  129. package/templates/react/src/App.tsx +42 -0
  130. package/templates/react/src/artifacts/greeter.ral.json +26 -0
  131. package/templates/react/src/artifacts/greeter_main.ral.json +22 -0
  132. package/templates/shared/.eslintrc.json +12 -0
  133. package/templates/shared/scripts/header.js +0 -0
  134. package/test/contract.test.ts +161 -0
  135. package/test/events.test.ts +138 -0
  136. package/test/transaction.test.ts +72 -0
  137. package/webpack.config.js +57 -0
@@ -0,0 +1,182 @@
1
+ import { NodeProvider } from '../api';
2
+ import { node } from '../api';
3
+ import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerWithNodeProvider } from '../signer';
4
+ export declare abstract class Common {
5
+ readonly sourceCodeSha256: string;
6
+ readonly functions: node.FunctionSig[];
7
+ static readonly importRegex: RegExp;
8
+ static readonly contractRegex: RegExp;
9
+ static readonly interfaceRegex: RegExp;
10
+ static readonly scriptRegex: RegExp;
11
+ private static _artifactCache;
12
+ static artifactCacheCapacity: number;
13
+ protected static _getArtifactFromCache(codeHash: string): Contract | Script | undefined;
14
+ protected static _putArtifactToCache(contract: Contract): void;
15
+ constructor(sourceCodeSha256: string, functions: node.FunctionSig[]);
16
+ protected static _contractPath(fileName: string): string;
17
+ protected static _artifactPath(fileName: string): string;
18
+ protected static _artifactsFolder(): string;
19
+ protected static _handleImports(contractStr: string, importsCache: string[]): Promise<string>;
20
+ protected static _loadContractStr(fileName: string, importsCache: string[], validate: (fileName: string) => void): Promise<string>;
21
+ static checkFileNameExtension(fileName: string): void;
22
+ protected static _from<T extends {
23
+ sourceCodeSha256: string;
24
+ }>(provider: NodeProvider, fileName: string, loadContractStr: (fileName: string, importsCache: string[]) => Promise<string>, compile: (provider: NodeProvider, fileName: string, contractStr: string, contractHash: string) => Promise<T>): Promise<T>;
25
+ protected _saveToFile(fileName: string): Promise<void>;
26
+ abstract buildByteCodeToDeploy(initialFields?: Fields): string;
27
+ }
28
+ export declare class Contract extends Common {
29
+ readonly bytecode: string;
30
+ readonly codeHash: string;
31
+ readonly fieldsSig: node.FieldsSig;
32
+ readonly eventsSig: node.EventSig[];
33
+ constructor(sourceCodeSha256: string, bytecode: string, codeHash: string, fieldsSig: node.FieldsSig, eventsSig: node.EventSig[], functions: node.FunctionSig[]);
34
+ static checkCodeType(fileName: string, contractStr: string): void;
35
+ private static loadContractStr;
36
+ static fromSource(provider: NodeProvider, fileName: string): Promise<Contract>;
37
+ private static compile;
38
+ static fromJson(artifact: any): Contract;
39
+ static fromArtifactFile(fileName: string): Promise<Contract>;
40
+ toString(): string;
41
+ toState(fields: Fields, asset: Asset, address?: string): ContractState;
42
+ static randomAddress(): string;
43
+ private _test;
44
+ testPublicMethod(provider: NodeProvider, funcName: string, params: TestContractParams): Promise<TestContractResult>;
45
+ testPrivateMethod(provider: NodeProvider, funcName: string, params: TestContractParams): Promise<TestContractResult>;
46
+ toApiFields(fields?: Fields): node.Val[];
47
+ toApiArgs(funcName: string, args?: Arguments): node.Val[];
48
+ getMethodIndex(funcName: string): number;
49
+ toApiContractStates(states?: ContractState[]): node.ContractState[] | undefined;
50
+ toTestContract(funcName: string, params: TestContractParams): node.TestContract;
51
+ static fromCodeHash(codeHash: string): Promise<Contract>;
52
+ static getFieldsSig(state: node.ContractState): Promise<node.FieldsSig>;
53
+ fromApiContractState(state: node.ContractState): Promise<ContractState>;
54
+ static ContractCreatedEvent: node.EventSig;
55
+ static ContractDestroyedEvent: node.EventSig;
56
+ static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): Promise<ContractEventByTxId>;
57
+ fromTestContractResult(methodIndex: number, result: node.TestContractResult): Promise<TestContractResult>;
58
+ paramsForDeployment(params: BuildDeployContractTx): Promise<SignDeployContractTxParams>;
59
+ transactionForDeployment(signer: SignerWithNodeProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<DeployContractTransaction>;
60
+ buildByteCodeToDeploy(initialFields: Fields): string;
61
+ }
62
+ export declare class Script extends Common {
63
+ readonly bytecodeTemplate: string;
64
+ readonly fieldsSig: node.FieldsSig;
65
+ constructor(sourceCodeSha256: string, bytecodeTemplate: string, fieldsSig: node.FieldsSig, functions: node.FunctionSig[]);
66
+ static checkCodeType(fileName: string, contractStr: string): void;
67
+ private static loadContractStr;
68
+ static fromSource(provider: NodeProvider, fileName: string): Promise<Script>;
69
+ private static compile;
70
+ static fromJson(artifact: any): Script;
71
+ static fromArtifactFile(fileName: string): Promise<Script>;
72
+ toString(): string;
73
+ paramsForDeployment(params: BuildExecuteScriptTx): Promise<SignExecuteScriptTxParams>;
74
+ transactionForDeployment(signer: SignerWithNodeProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<BuildScriptTxResult>;
75
+ buildByteCodeToDeploy(initialFields: Fields): string;
76
+ }
77
+ export declare type Number256 = number | bigint | string;
78
+ export declare type Val = Number256 | boolean | string | Val[];
79
+ export declare type NamedVals = Record<string, Val>;
80
+ export declare type Fields = NamedVals;
81
+ export declare type Arguments = NamedVals;
82
+ export declare function extractArray(tpe: string, v: Val): node.Val;
83
+ export declare function toApiVal(v: Val, tpe: string): node.Val;
84
+ export interface Asset {
85
+ alphAmount: Number256;
86
+ tokens?: Token[];
87
+ }
88
+ export interface Token {
89
+ id: string;
90
+ amount: Number256;
91
+ }
92
+ export interface InputAsset {
93
+ address: string;
94
+ asset: Asset;
95
+ }
96
+ export interface ContractState {
97
+ address: string;
98
+ contractId: string;
99
+ bytecode: string;
100
+ initialStateHash?: string;
101
+ codeHash: string;
102
+ fields: Fields;
103
+ fieldsSig: node.FieldsSig;
104
+ asset: Asset;
105
+ }
106
+ export interface TestContractParams {
107
+ group?: number;
108
+ address?: string;
109
+ initialFields?: Fields;
110
+ initialAsset?: Asset;
111
+ testMethodIndex?: number;
112
+ testArgs?: Arguments;
113
+ existingContracts?: ContractState[];
114
+ inputAssets?: InputAsset[];
115
+ }
116
+ export interface ContractEvent {
117
+ blockHash: string;
118
+ txId: string;
119
+ name: string;
120
+ fields: Fields;
121
+ }
122
+ export interface ContractEventByTxId {
123
+ blockHash: string;
124
+ contractAddress: string;
125
+ name: string;
126
+ fields: Fields;
127
+ }
128
+ export interface TestContractResult {
129
+ address: string;
130
+ contractId: string;
131
+ returns: Val[];
132
+ gasUsed: number;
133
+ contracts: ContractState[];
134
+ txOutputs: Output[];
135
+ events: ContractEventByTxId[];
136
+ }
137
+ export declare type Output = AssetOutput | ContractOutput;
138
+ export interface AssetOutput extends Asset {
139
+ type: string;
140
+ address: string;
141
+ lockTime: number;
142
+ message: string;
143
+ }
144
+ export interface ContractOutput {
145
+ type: string;
146
+ address: string;
147
+ alphAmount: Number256;
148
+ tokens: Token[];
149
+ }
150
+ export interface DeployContractTransaction {
151
+ fromGroup: number;
152
+ toGroup: number;
153
+ unsignedTx: string;
154
+ txId: string;
155
+ contractAddress: string;
156
+ contractId: string;
157
+ }
158
+ export interface BuildDeployContractTx {
159
+ signerAddress: string;
160
+ initialFields?: Fields;
161
+ initialAttoAlphAmount?: string;
162
+ initialTokenAmounts?: Token[];
163
+ issueTokenAmount?: Number256;
164
+ gasAmount?: number;
165
+ gasPrice?: Number256;
166
+ submitTx?: boolean;
167
+ }
168
+ export interface BuildExecuteScriptTx {
169
+ signerAddress: string;
170
+ initialFields?: Fields;
171
+ attoAlphAmount?: Number256;
172
+ tokens?: Token[];
173
+ gasAmount?: number;
174
+ gasPrice?: Number256;
175
+ submitTx?: boolean;
176
+ }
177
+ export interface BuildScriptTxResult {
178
+ fromGroup: number;
179
+ toGroup: number;
180
+ unsignedTx: string;
181
+ txId: string;
182
+ }