@alephium/web3 0.2.0-rc.0 → 0.2.0-rc.11

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 (98) hide show
  1. package/.eslintignore +2 -2
  2. package/README.md +2 -135
  3. package/contracts/greeter/greeter.ral +3 -3
  4. package/contracts/greeter/greeter_interface.ral +1 -0
  5. package/contracts/greeter_main.ral +3 -5
  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 +46 -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 +3 -2
  15. package/dist/src/api/index.js +22 -3
  16. package/dist/src/api/types.d.ts +23 -0
  17. package/dist/src/api/types.js +240 -0
  18. package/dist/src/contract/contract.d.ts +104 -64
  19. package/dist/src/contract/contract.js +370 -426
  20. package/dist/src/contract/events.d.ts +4 -4
  21. package/dist/src/contract/index.js +5 -1
  22. package/dist/src/contract/ralph.d.ts +4 -4
  23. package/dist/src/global.d.ts +4 -0
  24. package/dist/src/global.js +38 -0
  25. package/dist/src/index.d.ts +2 -0
  26. package/dist/src/index.js +20 -1
  27. package/dist/src/signer/index.d.ts +0 -1
  28. package/dist/src/signer/index.js +5 -2
  29. package/dist/src/signer/signer.d.ts +21 -11
  30. package/dist/src/signer/signer.js +46 -9
  31. package/dist/src/transaction/index.d.ts +0 -1
  32. package/dist/src/transaction/index.js +5 -2
  33. package/dist/src/transaction/status.d.ts +2 -1
  34. package/dist/src/utils/index.d.ts +0 -1
  35. package/dist/src/utils/index.js +5 -2
  36. package/dist/src/utils/subscription.d.ts +0 -1
  37. package/dist/src/utils/subscription.js +2 -1
  38. package/dist/src/utils/utils.d.ts +5 -4
  39. package/dist/src/utils/utils.js +18 -17
  40. package/jest-config.json +11 -0
  41. package/package.json +7 -35
  42. package/scripts/create-project.ts +3 -2
  43. package/src/api/api-alephium.ts +56 -8
  44. package/src/api/api-explorer.ts +30 -0
  45. package/src/api/index.ts +14 -3
  46. package/src/api/types.ts +233 -0
  47. package/src/contract/contract.ts +537 -526
  48. package/src/contract/events.ts +6 -6
  49. package/src/contract/ralph.ts +4 -4
  50. package/src/{transaction/sign-verify.ts → global.ts} +14 -15
  51. package/src/index.ts +3 -0
  52. package/src/signer/index.ts +0 -1
  53. package/src/signer/signer.ts +70 -19
  54. package/src/transaction/index.ts +0 -1
  55. package/src/transaction/status.ts +4 -2
  56. package/src/utils/index.ts +0 -1
  57. package/src/utils/subscription.ts +3 -3
  58. package/src/utils/utils.ts +11 -11
  59. package/templates/base/package.json +2 -2
  60. package/templates/base/src/greeter.ts +10 -9
  61. package/templates/react/package.json +2 -2
  62. package/templates/react/src/App.tsx +2 -2
  63. package/.eslintrc.json +0 -21
  64. package/LICENSE +0 -165
  65. package/contracts/add/add.ral +0 -16
  66. package/contracts/main.ral +0 -6
  67. package/contracts/sub/sub.ral +0 -9
  68. package/dist/src/signer/node-wallet.d.ts +0 -13
  69. package/dist/src/signer/node-wallet.js +0 -60
  70. package/dist/src/test/index.d.ts +0 -7
  71. package/dist/src/test/index.js +0 -41
  72. package/dist/src/test/privatekey-wallet.d.ts +0 -12
  73. package/dist/src/test/privatekey-wallet.js +0 -68
  74. package/dist/src/transaction/sign-verify.d.ts +0 -2
  75. package/dist/src/transaction/sign-verify.js +0 -58
  76. package/dist/src/utils/password-crypto.d.ts +0 -2
  77. package/dist/src/utils/password-crypto.js +0 -69
  78. package/gitignore +0 -10
  79. package/src/contract/ralph.test.ts +0 -178
  80. package/src/fixtures/address.json +0 -36
  81. package/src/fixtures/balance.json +0 -9
  82. package/src/fixtures/self-clique.json +0 -19
  83. package/src/fixtures/transaction.json +0 -13
  84. package/src/fixtures/transactions.json +0 -179
  85. package/src/signer/fixtures/genesis.json +0 -26
  86. package/src/signer/fixtures/wallets.json +0 -26
  87. package/src/signer/node-wallet.ts +0 -74
  88. package/src/test/index.ts +0 -32
  89. package/src/test/privatekey-wallet.ts +0 -58
  90. package/src/transaction/sign-verify.test.ts +0 -50
  91. package/src/utils/address.test.ts +0 -47
  92. package/src/utils/djb2.test.ts +0 -35
  93. package/src/utils/password-crypto.test.ts +0 -27
  94. package/src/utils/password-crypto.ts +0 -77
  95. package/src/utils/utils.test.ts +0 -161
  96. package/test/contract.test.ts +0 -178
  97. package/test/events.test.ts +0 -138
  98. package/test/transaction.test.ts +0 -72
@@ -1,79 +1,130 @@
1
- import { NodeProvider } from '../api';
2
- import { node } from '../api';
1
+ import { NamedVals, node, NodeProvider, Number256, Token, Val } from '../api';
3
2
  import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerWithNodeProvider } from '../signer';
3
+ export declare type FieldsSig = node.FieldsSig;
4
+ export declare type EventSig = node.EventSig;
5
+ export declare type FunctionSig = node.FunctionSig;
6
+ export declare type Fields = NamedVals;
7
+ export declare type Arguments = NamedVals;
8
+ declare enum SourceType {
9
+ Contract = 0,
10
+ Script = 1,
11
+ AbstractContract = 2,
12
+ Interface = 3
13
+ }
14
+ export declare type CompilerOptions = node.CompilerOptions & {
15
+ errorOnWarnings: boolean;
16
+ };
17
+ export declare const DEFAULT_NODE_COMPILER_OPTIONS: node.CompilerOptions;
18
+ export declare const DEFAULT_COMPILER_OPTIONS: CompilerOptions;
19
+ declare class TypedMatcher<T extends SourceType> {
20
+ matcher: RegExp;
21
+ type: T;
22
+ constructor(pattern: string, type: T);
23
+ match(str: string): number;
24
+ }
4
25
  declare class SourceFile {
5
- readonly dirs: string[];
6
- readonly dirPath: string;
7
- readonly contractPath: string;
8
- readonly artifactPath: string;
9
- constructor(dirs: string[], fileName: string);
10
- }
11
- export declare abstract class Common {
12
- readonly sourceCodeSha256: string;
13
- readonly functions: node.FunctionSig[];
14
- static readonly importRegex: RegExp;
15
- static readonly contractRegex: RegExp;
16
- static readonly interfaceRegex: RegExp;
17
- static readonly scriptRegex: RegExp;
18
- private static _artifactCache;
19
- static artifactCacheCapacity: number;
20
- protected static _getArtifactFromCache(codeHash: string): Contract | Script | undefined;
21
- protected static _putArtifactToCache(contract: Contract): void;
22
- constructor(sourceCodeSha256: string, functions: node.FunctionSig[]);
23
- protected static _artifactsFolder(): string;
24
- static getSourceFile(path: string, _dirs: string[]): SourceFile;
25
- protected static _handleImports(pathes: string[], contractStr: string, importsCache: string[]): Promise<string>;
26
- protected static _loadContractStr(sourceFile: SourceFile, importsCache: string[], validate: (code: string) => void): Promise<string>;
27
- static checkFileNameExtension(fileName: string): void;
28
- protected static _from<T extends {
29
- sourceCodeSha256: string;
30
- }>(provider: NodeProvider, sourceFile: SourceFile, loadContractStr: (sourceFile: SourceFile, importsCache: string[]) => Promise<string>, compile: (provider: NodeProvider, sourceFile: SourceFile, contractStr: string, contractHash: string) => Promise<T>): Promise<T>;
31
- protected _saveToFile(sourceFile: SourceFile): Promise<void>;
26
+ type: SourceType;
27
+ contractPath: string;
28
+ sourceCode: string;
29
+ sourceCodeHash: string;
30
+ getArtifactPath(artifactsRootPath: string): string;
31
+ constructor(type: SourceType, sourceCode: string, sourceCodeHash: string, contractPath: string);
32
+ static from(type: SourceType, sourceCode: string, contractPath: string): Promise<SourceFile>;
33
+ }
34
+ declare class Compiled<T extends Artifact> {
35
+ sourceFile: SourceFile;
36
+ artifact: T;
37
+ warnings: string[];
38
+ constructor(sourceFile: SourceFile, artifact: T, warnings: string[]);
39
+ }
40
+ declare class ProjectArtifact {
41
+ static readonly artifactFileName = ".project.json";
42
+ compilerOptionsUsed: node.CompilerOptions;
43
+ infos: Map<string, {
44
+ sourceCodeHash: string;
45
+ warnings: string[];
46
+ }>;
47
+ static checkCompilerOptionsParameter(compilerOptions: node.CompilerOptions): void;
48
+ constructor(compilerOptionsUsed: node.CompilerOptions, infos: Map<string, {
49
+ sourceCodeHash: string;
50
+ warnings: string[];
51
+ }>);
52
+ saveToFile(rootPath: string): Promise<void>;
53
+ needToReCompile(compilerOptions: node.CompilerOptions, files: SourceFile[]): boolean;
54
+ static from(rootPath: string): Promise<ProjectArtifact | undefined>;
55
+ }
56
+ export declare class Project {
57
+ sourceFiles: SourceFile[];
58
+ contracts: Compiled<Contract>[];
59
+ scripts: Compiled<Script>[];
60
+ projectArtifact: ProjectArtifact;
61
+ readonly contractsRootPath: string;
62
+ readonly artifactsRootPath: string;
63
+ readonly nodeProvider: NodeProvider;
64
+ static currentProject: Project;
65
+ static readonly abstractContractMatcher: TypedMatcher<SourceType>;
66
+ static readonly contractMatcher: TypedMatcher<SourceType.Contract>;
67
+ static readonly interfaceMatcher: TypedMatcher<SourceType.Interface>;
68
+ static readonly scriptMatcher: TypedMatcher<SourceType.Script>;
69
+ static readonly matchers: TypedMatcher<SourceType>[];
70
+ static buildProjectArtifact(sourceFiles: SourceFile[], contracts: Compiled<Contract>[], scripts: Compiled<Script>[], compilerOptions: node.CompilerOptions): ProjectArtifact;
71
+ private constructor();
72
+ private getContractPath;
73
+ static checkCompilerWarnings(warnings: string[], errorOnWarnings: boolean): void;
74
+ static contract(name: string): Contract;
75
+ static script(name: string): Script;
76
+ private saveArtifactsToFile;
77
+ contractByCodeHash(codeHash: string): Contract;
78
+ private static compile;
79
+ private static loadArtifacts;
80
+ private static loadSourceFile;
81
+ private static loadSourceFiles;
82
+ static build(compilerOptionsPartial?: Partial<CompilerOptions>, contractsRootPath?: string, artifactsRootPath?: string): Promise<void>;
83
+ }
84
+ export declare abstract class Artifact {
85
+ readonly name: string;
86
+ readonly functions: FunctionSig[];
87
+ constructor(name: string, functions: FunctionSig[]);
32
88
  abstract buildByteCodeToDeploy(initialFields?: Fields): string;
89
+ publicFunctions(): string[];
90
+ usingPreapprovedAssetsFunctions(): string[];
91
+ usingAssetsInContractFunctions(): string[];
33
92
  }
34
- export declare class Contract extends Common {
93
+ export declare class Contract extends Artifact {
35
94
  readonly bytecode: string;
36
95
  readonly codeHash: string;
37
- readonly fieldsSig: node.FieldsSig;
38
- readonly eventsSig: node.EventSig[];
39
- constructor(sourceCodeSha256: string, bytecode: string, codeHash: string, fieldsSig: node.FieldsSig, eventsSig: node.EventSig[], functions: node.FunctionSig[]);
40
- static checkCodeType(fileName: string, contractStr: string): void;
41
- private static loadContractStr;
42
- static fromSource(provider: NodeProvider, path: string): Promise<Contract>;
43
- private static compile;
96
+ readonly fieldsSig: FieldsSig;
97
+ readonly eventsSig: EventSig[];
98
+ constructor(name: string, bytecode: string, codeHash: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[]);
44
99
  static fromJson(artifact: any): Contract;
100
+ static fromCompileResult(result: node.CompileContractResult): Contract;
45
101
  static fromArtifactFile(path: string): Promise<Contract>;
46
- fetchState(provider: NodeProvider, address: string, group: number): Promise<ContractState>;
102
+ fetchState(address: string, group: number): Promise<ContractState>;
47
103
  toString(): string;
48
104
  toState(fields: Fields, asset: Asset, address?: string): ContractState;
49
105
  static randomAddress(): string;
50
106
  private _test;
51
- testPublicMethod(provider: NodeProvider, funcName: string, params: TestContractParams): Promise<TestContractResult>;
52
- testPrivateMethod(provider: NodeProvider, funcName: string, params: TestContractParams): Promise<TestContractResult>;
107
+ testPublicMethod(funcName: string, params: TestContractParams): Promise<TestContractResult>;
108
+ testPrivateMethod(funcName: string, params: TestContractParams): Promise<TestContractResult>;
53
109
  toApiFields(fields?: Fields): node.Val[];
54
110
  toApiArgs(funcName: string, args?: Arguments): node.Val[];
55
111
  getMethodIndex(funcName: string): number;
56
112
  toApiContractStates(states?: ContractState[]): node.ContractState[] | undefined;
57
113
  toTestContract(funcName: string, params: TestContractParams): node.TestContract;
58
- static fromCodeHash(codeHash: string): Promise<Contract>;
59
- static getFieldsSig(state: node.ContractState): Promise<node.FieldsSig>;
60
114
  fromApiContractState(state: node.ContractState): Promise<ContractState>;
61
- static ContractCreatedEvent: node.EventSig;
62
- static ContractDestroyedEvent: node.EventSig;
115
+ static ContractCreatedEvent: EventSig;
116
+ static ContractDestroyedEvent: EventSig;
63
117
  static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): Promise<ContractEventByTxId>;
64
118
  fromTestContractResult(methodIndex: number, result: node.TestContractResult): Promise<TestContractResult>;
65
119
  paramsForDeployment(params: BuildDeployContractTx): Promise<SignDeployContractTxParams>;
66
120
  transactionForDeployment(signer: SignerWithNodeProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<DeployContractTransaction>;
67
121
  buildByteCodeToDeploy(initialFields: Fields): string;
68
122
  }
69
- export declare class Script extends Common {
123
+ export declare class Script extends Artifact {
70
124
  readonly bytecodeTemplate: string;
71
- readonly fieldsSig: node.FieldsSig;
72
- constructor(sourceCodeSha256: string, bytecodeTemplate: string, fieldsSig: node.FieldsSig, functions: node.FunctionSig[]);
73
- static checkCodeType(fileName: string, contractStr: string): void;
74
- private static loadContractStr;
75
- static fromSource(provider: NodeProvider, path: string): Promise<Script>;
76
- private static compile;
125
+ readonly fieldsSig: FieldsSig;
126
+ constructor(name: string, bytecodeTemplate: string, fieldsSig: FieldsSig, functions: FunctionSig[]);
127
+ static fromCompileResult(result: node.CompileScriptResult): Script;
77
128
  static fromJson(artifact: any): Script;
78
129
  static fromArtifactFile(path: string): Promise<Script>;
79
130
  toString(): string;
@@ -81,21 +132,10 @@ export declare class Script extends Common {
81
132
  transactionForDeployment(signer: SignerWithNodeProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<BuildScriptTxResult>;
82
133
  buildByteCodeToDeploy(initialFields: Fields): string;
83
134
  }
84
- export declare type Number256 = number | bigint | string;
85
- export declare type Val = Number256 | boolean | string | Val[];
86
- export declare type NamedVals = Record<string, Val>;
87
- export declare type Fields = NamedVals;
88
- export declare type Arguments = NamedVals;
89
- export declare function extractArray(tpe: string, v: Val): node.Val;
90
- export declare function toApiVal(v: Val, tpe: string): node.Val;
91
135
  export interface Asset {
92
136
  alphAmount: Number256;
93
137
  tokens?: Token[];
94
138
  }
95
- export interface Token {
96
- id: string;
97
- amount: Number256;
98
- }
99
139
  export interface InputAsset {
100
140
  address: string;
101
141
  asset: Asset;
@@ -107,7 +147,7 @@ export interface ContractState {
107
147
  initialStateHash?: string;
108
148
  codeHash: string;
109
149
  fields: Fields;
110
- fieldsSig: node.FieldsSig;
150
+ fieldsSig: FieldsSig;
111
151
  asset: Asset;
112
152
  }
113
153
  export interface TestContractParams {
@@ -152,7 +192,7 @@ export interface ContractOutput {
152
192
  type: string;
153
193
  address: string;
154
194
  alphAmount: Number256;
155
- tokens: Token[];
195
+ tokens?: Token[];
156
196
  }
157
197
  export interface DeployContractTransaction {
158
198
  fromGroup: number;