@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.
- package/.eslintignore +2 -2
- package/README.md +2 -135
- package/contracts/greeter/greeter.ral +3 -3
- package/contracts/greeter/greeter_interface.ral +1 -0
- package/contracts/greeter_main.ral +3 -5
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.LICENSE.txt +0 -17
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/scripts/create-project.js +3 -2
- package/dist/src/api/api-alephium.d.ts +46 -13
- package/dist/src/api/api-alephium.js +19 -3
- package/dist/src/api/api-explorer.d.ts +32 -16
- package/dist/src/api/api-explorer.js +26 -0
- package/dist/src/api/index.d.ts +3 -2
- package/dist/src/api/index.js +22 -3
- package/dist/src/api/types.d.ts +23 -0
- package/dist/src/api/types.js +240 -0
- package/dist/src/contract/contract.d.ts +104 -64
- package/dist/src/contract/contract.js +370 -426
- package/dist/src/contract/events.d.ts +4 -4
- package/dist/src/contract/index.js +5 -1
- package/dist/src/contract/ralph.d.ts +4 -4
- package/dist/src/global.d.ts +4 -0
- package/dist/src/global.js +38 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +20 -1
- package/dist/src/signer/index.d.ts +0 -1
- package/dist/src/signer/index.js +5 -2
- package/dist/src/signer/signer.d.ts +21 -11
- package/dist/src/signer/signer.js +46 -9
- package/dist/src/transaction/index.d.ts +0 -1
- package/dist/src/transaction/index.js +5 -2
- package/dist/src/transaction/status.d.ts +2 -1
- package/dist/src/utils/index.d.ts +0 -1
- package/dist/src/utils/index.js +5 -2
- package/dist/src/utils/subscription.d.ts +0 -1
- package/dist/src/utils/subscription.js +2 -1
- package/dist/src/utils/utils.d.ts +5 -4
- package/dist/src/utils/utils.js +18 -17
- package/jest-config.json +11 -0
- package/package.json +7 -35
- package/scripts/create-project.ts +3 -2
- package/src/api/api-alephium.ts +56 -8
- package/src/api/api-explorer.ts +30 -0
- package/src/api/index.ts +14 -3
- package/src/api/types.ts +233 -0
- package/src/contract/contract.ts +537 -526
- package/src/contract/events.ts +6 -6
- package/src/contract/ralph.ts +4 -4
- package/src/{transaction/sign-verify.ts → global.ts} +14 -15
- package/src/index.ts +3 -0
- package/src/signer/index.ts +0 -1
- package/src/signer/signer.ts +70 -19
- package/src/transaction/index.ts +0 -1
- package/src/transaction/status.ts +4 -2
- package/src/utils/index.ts +0 -1
- package/src/utils/subscription.ts +3 -3
- package/src/utils/utils.ts +11 -11
- package/templates/base/package.json +2 -2
- package/templates/base/src/greeter.ts +10 -9
- package/templates/react/package.json +2 -2
- package/templates/react/src/App.tsx +2 -2
- package/.eslintrc.json +0 -21
- package/LICENSE +0 -165
- package/contracts/add/add.ral +0 -16
- package/contracts/main.ral +0 -6
- package/contracts/sub/sub.ral +0 -9
- package/dist/src/signer/node-wallet.d.ts +0 -13
- package/dist/src/signer/node-wallet.js +0 -60
- package/dist/src/test/index.d.ts +0 -7
- package/dist/src/test/index.js +0 -41
- package/dist/src/test/privatekey-wallet.d.ts +0 -12
- package/dist/src/test/privatekey-wallet.js +0 -68
- package/dist/src/transaction/sign-verify.d.ts +0 -2
- package/dist/src/transaction/sign-verify.js +0 -58
- package/dist/src/utils/password-crypto.d.ts +0 -2
- package/dist/src/utils/password-crypto.js +0 -69
- package/gitignore +0 -10
- package/src/contract/ralph.test.ts +0 -178
- package/src/fixtures/address.json +0 -36
- package/src/fixtures/balance.json +0 -9
- package/src/fixtures/self-clique.json +0 -19
- package/src/fixtures/transaction.json +0 -13
- package/src/fixtures/transactions.json +0 -179
- package/src/signer/fixtures/genesis.json +0 -26
- package/src/signer/fixtures/wallets.json +0 -26
- package/src/signer/node-wallet.ts +0 -74
- package/src/test/index.ts +0 -32
- package/src/test/privatekey-wallet.ts +0 -58
- package/src/transaction/sign-verify.test.ts +0 -50
- package/src/utils/address.test.ts +0 -47
- package/src/utils/djb2.test.ts +0 -35
- package/src/utils/password-crypto.test.ts +0 -27
- package/src/utils/password-crypto.ts +0 -77
- package/src/utils/utils.test.ts +0 -161
- package/test/contract.test.ts +0 -178
- package/test/events.test.ts +0 -138
- 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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}>
|
|
31
|
-
|
|
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
|
|
93
|
+
export declare class Contract extends Artifact {
|
|
35
94
|
readonly bytecode: string;
|
|
36
95
|
readonly codeHash: string;
|
|
37
|
-
readonly fieldsSig:
|
|
38
|
-
readonly eventsSig:
|
|
39
|
-
constructor(
|
|
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(
|
|
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(
|
|
52
|
-
testPrivateMethod(
|
|
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:
|
|
62
|
-
static ContractDestroyedEvent:
|
|
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
|
|
123
|
+
export declare class Script extends Artifact {
|
|
70
124
|
readonly bytecodeTemplate: string;
|
|
71
|
-
readonly fieldsSig:
|
|
72
|
-
constructor(
|
|
73
|
-
static
|
|
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:
|
|
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
|
|
195
|
+
tokens?: Token[];
|
|
156
196
|
}
|
|
157
197
|
export interface DeployContractTransaction {
|
|
158
198
|
fromGroup: number;
|