@alephium/web3 0.3.0-rc.4 → 0.3.0-rc.7
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/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +1 -1
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/api/api-explorer.d.ts +91 -21
- package/dist/src/api/api-explorer.js +64 -31
- package/dist/src/api/index.d.ts +0 -1
- package/dist/src/api/index.js +0 -2
- package/dist/src/contract/contract.d.ts +21 -21
- package/dist/src/contract/contract.js +103 -108
- package/dist/src/signer/index.d.ts +2 -0
- package/dist/src/signer/index.js +2 -0
- package/dist/src/signer/signer.d.ts +30 -107
- package/dist/src/signer/signer.js +63 -68
- package/dist/src/signer/tx-builder.d.ts +17 -0
- package/dist/src/signer/tx-builder.js +93 -0
- package/dist/src/signer/types.d.ts +121 -0
- package/dist/src/signer/types.js +30 -0
- package/package.json +4 -3
- package/src/api/api-alephium.ts +1 -1
- package/src/api/api-explorer.ts +134 -36
- package/src/api/index.ts +0 -2
- package/src/contract/contract.ts +143 -121
- package/src/signer/index.ts +2 -0
- package/src/signer/signer.ts +112 -188
- package/src/signer/tx-builder.ts +121 -0
- package/src/signer/types.ts +155 -0
- package/webpack.config.js +1 -0
|
@@ -53,13 +53,14 @@ const ralph = __importStar(require("./ralph"));
|
|
|
53
53
|
const utils_1 = require("../utils");
|
|
54
54
|
const global_1 = require("../global");
|
|
55
55
|
const __1 = require("..");
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
const path = __importStar(require("path"));
|
|
57
|
+
var SourceKind;
|
|
58
|
+
(function (SourceKind) {
|
|
59
|
+
SourceKind[SourceKind["Contract"] = 0] = "Contract";
|
|
60
|
+
SourceKind[SourceKind["Script"] = 1] = "Script";
|
|
61
|
+
SourceKind[SourceKind["AbstractContract"] = 2] = "AbstractContract";
|
|
62
|
+
SourceKind[SourceKind["Interface"] = 3] = "Interface";
|
|
63
|
+
})(SourceKind || (SourceKind = {}));
|
|
63
64
|
exports.DEFAULT_NODE_COMPILER_OPTIONS = {
|
|
64
65
|
ignoreUnusedConstantsWarnings: false,
|
|
65
66
|
ignoreUnusedVariablesWarnings: false,
|
|
@@ -74,29 +75,26 @@ class TypedMatcher {
|
|
|
74
75
|
this.matcher = new RegExp(pattern, 'mg');
|
|
75
76
|
this.type = type;
|
|
76
77
|
}
|
|
77
|
-
match(str) {
|
|
78
|
-
const results = str.match(this.matcher);
|
|
79
|
-
return results === null ? 0 : results.length;
|
|
80
|
-
}
|
|
81
78
|
}
|
|
82
|
-
class
|
|
83
|
-
constructor(type, sourceCode, sourceCodeHash,
|
|
79
|
+
class SourceInfo {
|
|
80
|
+
constructor(type, name, sourceCode, sourceCodeHash, contractRelativePath) {
|
|
84
81
|
this.type = type;
|
|
82
|
+
this.name = name;
|
|
85
83
|
this.sourceCode = sourceCode;
|
|
86
84
|
this.sourceCodeHash = sourceCodeHash;
|
|
87
|
-
this.
|
|
85
|
+
this.contractRelativePath = contractRelativePath;
|
|
88
86
|
}
|
|
89
87
|
getArtifactPath(artifactsRootDir) {
|
|
90
|
-
return artifactsRootDir
|
|
88
|
+
return path.join(artifactsRootDir, this.contractRelativePath) + '.json';
|
|
91
89
|
}
|
|
92
|
-
static async from(type, sourceCode,
|
|
90
|
+
static async from(type, name, sourceCode, contractRelativePath) {
|
|
93
91
|
const sourceCodeHash = await crypto_1.webcrypto.subtle.digest('SHA-256', buffer_1.Buffer.from(sourceCode));
|
|
94
|
-
return new
|
|
92
|
+
return new SourceInfo(type, name, sourceCode, buffer_1.Buffer.from(sourceCodeHash).toString('hex'), contractRelativePath);
|
|
95
93
|
}
|
|
96
94
|
}
|
|
97
95
|
class Compiled {
|
|
98
|
-
constructor(
|
|
99
|
-
this.
|
|
96
|
+
constructor(sourceInfo, artifact, warnings) {
|
|
97
|
+
this.sourceInfo = sourceInfo;
|
|
100
98
|
this.artifact = artifact;
|
|
101
99
|
this.warnings = warnings;
|
|
102
100
|
}
|
|
@@ -117,12 +115,15 @@ class ProjectArtifact {
|
|
|
117
115
|
}
|
|
118
116
|
}
|
|
119
117
|
async saveToFile(rootPath) {
|
|
120
|
-
const filepath = rootPath
|
|
121
|
-
const artifact = {
|
|
118
|
+
const filepath = path.join(rootPath, ProjectArtifact.artifactFileName);
|
|
119
|
+
const artifact = {
|
|
120
|
+
compilerOptionsUsed: this.compilerOptionsUsed,
|
|
121
|
+
infos: Object.fromEntries(new Map([...this.infos].sort()))
|
|
122
|
+
};
|
|
122
123
|
const content = JSON.stringify(artifact, null, 2);
|
|
123
124
|
return fs_2.promises.writeFile(filepath, content);
|
|
124
125
|
}
|
|
125
|
-
needToReCompile(compilerOptions,
|
|
126
|
+
needToReCompile(compilerOptions, sourceInfos) {
|
|
126
127
|
ProjectArtifact.checkCompilerOptionsParameter(compilerOptions);
|
|
127
128
|
const optionsMatched = Object.entries(compilerOptions).every(([key, inputOption]) => {
|
|
128
129
|
const usedOption = this.compilerOptionsUsed[`${key}`];
|
|
@@ -131,19 +132,19 @@ class ProjectArtifact {
|
|
|
131
132
|
if (!optionsMatched) {
|
|
132
133
|
return true;
|
|
133
134
|
}
|
|
134
|
-
if (
|
|
135
|
+
if (sourceInfos.length !== this.infos.size) {
|
|
135
136
|
return true;
|
|
136
137
|
}
|
|
137
|
-
for (const
|
|
138
|
-
const info = this.infos.get(
|
|
139
|
-
if (typeof info === 'undefined' || info.sourceCodeHash !==
|
|
138
|
+
for (const sourceInfo of sourceInfos) {
|
|
139
|
+
const info = this.infos.get(sourceInfo.name);
|
|
140
|
+
if (typeof info === 'undefined' || info.sourceCodeHash !== sourceInfo.sourceCodeHash) {
|
|
140
141
|
return true;
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
144
|
return false;
|
|
144
145
|
}
|
|
145
146
|
static async from(rootPath) {
|
|
146
|
-
const filepath = rootPath
|
|
147
|
+
const filepath = path.join(rootPath, ProjectArtifact.artifactFileName);
|
|
147
148
|
if (!fs_1.default.existsSync(filepath)) {
|
|
148
149
|
return undefined;
|
|
149
150
|
}
|
|
@@ -156,38 +157,44 @@ class ProjectArtifact {
|
|
|
156
157
|
}
|
|
157
158
|
ProjectArtifact.artifactFileName = '.project.json';
|
|
158
159
|
class Project {
|
|
159
|
-
constructor(contractsRootDir, artifactsRootDir,
|
|
160
|
+
constructor(contractsRootDir, artifactsRootDir, sourceInfos, contracts, scripts, errorOnWarnings, projectArtifact) {
|
|
160
161
|
this.contractsRootDir = contractsRootDir;
|
|
161
162
|
this.artifactsRootDir = artifactsRootDir;
|
|
162
|
-
this.
|
|
163
|
+
this.sourceInfos = sourceInfos;
|
|
163
164
|
this.contracts = contracts;
|
|
164
165
|
this.scripts = scripts;
|
|
165
166
|
this.projectArtifact = projectArtifact;
|
|
166
167
|
if (errorOnWarnings) {
|
|
167
|
-
Project.checkCompilerWarnings([
|
|
168
|
+
Project.checkCompilerWarnings([
|
|
169
|
+
...[...contracts.entries()].map((c) => c[1].warnings).flat(),
|
|
170
|
+
...[...scripts.entries()].map((s) => s[1].warnings).flat()
|
|
171
|
+
], errorOnWarnings);
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
|
-
static buildProjectArtifact(
|
|
174
|
+
static buildProjectArtifact(sourceInfos, contracts, scripts, compilerOptions) {
|
|
171
175
|
const files = new Map();
|
|
172
176
|
contracts.forEach((c) => {
|
|
173
|
-
files.set(c.
|
|
174
|
-
|
|
177
|
+
files.set(c.artifact.name, {
|
|
178
|
+
sourceFile: c.sourceInfo.contractRelativePath,
|
|
179
|
+
sourceCodeHash: c.sourceInfo.sourceCodeHash,
|
|
175
180
|
bytecodeDebugPatch: c.artifact.bytecodeDebugPatch,
|
|
176
181
|
codeHashDebug: c.artifact.codeHashDebug,
|
|
177
182
|
warnings: c.warnings
|
|
178
183
|
});
|
|
179
184
|
});
|
|
180
185
|
scripts.forEach((s) => {
|
|
181
|
-
files.set(s.
|
|
182
|
-
|
|
186
|
+
files.set(s.artifact.name, {
|
|
187
|
+
sourceFile: s.sourceInfo.contractRelativePath,
|
|
188
|
+
sourceCodeHash: s.sourceInfo.sourceCodeHash,
|
|
183
189
|
bytecodeDebugPatch: s.artifact.bytecodeDebugPatch,
|
|
184
190
|
codeHashDebug: '',
|
|
185
191
|
warnings: s.warnings
|
|
186
192
|
});
|
|
187
193
|
});
|
|
188
|
-
const compiledSize = contracts.
|
|
189
|
-
|
|
190
|
-
files.set(c.
|
|
194
|
+
const compiledSize = contracts.size + scripts.size;
|
|
195
|
+
sourceInfos.slice(compiledSize).forEach((c) => {
|
|
196
|
+
files.set(c.name, {
|
|
197
|
+
sourceFile: c.contractRelativePath,
|
|
191
198
|
sourceCodeHash: c.sourceCodeHash,
|
|
192
199
|
bytecodeDebugPatch: '',
|
|
193
200
|
codeHashDebug: '',
|
|
@@ -196,13 +203,6 @@ class Project {
|
|
|
196
203
|
});
|
|
197
204
|
return new ProjectArtifact(compilerOptions, files);
|
|
198
205
|
}
|
|
199
|
-
getContractPath(path) {
|
|
200
|
-
return path.startsWith(`./${this.contractsRootDir}`)
|
|
201
|
-
? path.slice(2)
|
|
202
|
-
: path.startsWith(this.contractsRootDir)
|
|
203
|
-
? path
|
|
204
|
-
: this.contractsRootDir + '/' + path;
|
|
205
|
-
}
|
|
206
206
|
static checkCompilerWarnings(warnings, errorOnWarnings) {
|
|
207
207
|
if (warnings.length !== 0) {
|
|
208
208
|
const prefixPerWarning = ' - ';
|
|
@@ -217,14 +217,14 @@ class Project {
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
static contract(name) {
|
|
220
|
-
const contract = Project.currentProject.contracts.
|
|
220
|
+
const contract = Project.currentProject.contracts.get(name);
|
|
221
221
|
if (typeof contract === 'undefined') {
|
|
222
222
|
throw new Error(`Contract "${name}" does not exist`);
|
|
223
223
|
}
|
|
224
224
|
return contract.artifact;
|
|
225
225
|
}
|
|
226
226
|
static script(name) {
|
|
227
|
-
const script = Project.currentProject.scripts.
|
|
227
|
+
const script = Project.currentProject.scripts.get(name);
|
|
228
228
|
if (typeof script === 'undefined') {
|
|
229
229
|
throw new Error(`Script "${name}" does not exist`);
|
|
230
230
|
}
|
|
@@ -233,118 +233,113 @@ class Project {
|
|
|
233
233
|
async saveArtifactsToFile() {
|
|
234
234
|
const artifactsRootDir = this.artifactsRootDir;
|
|
235
235
|
const saveToFile = async function (compiled) {
|
|
236
|
-
const
|
|
237
|
-
const
|
|
238
|
-
if (!fs_1.default.existsSync(
|
|
239
|
-
fs_1.default.mkdirSync(
|
|
236
|
+
const artifactPath = compiled.sourceInfo.getArtifactPath(artifactsRootDir);
|
|
237
|
+
const dirname = path.dirname(artifactPath);
|
|
238
|
+
if (!fs_1.default.existsSync(dirname)) {
|
|
239
|
+
fs_1.default.mkdirSync(dirname, { recursive: true });
|
|
240
240
|
}
|
|
241
|
-
return fs_2.promises.writeFile(
|
|
241
|
+
return fs_2.promises.writeFile(artifactPath, compiled.artifact.toString());
|
|
242
242
|
};
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
for (const script of this.scripts) {
|
|
247
|
-
await saveToFile(script);
|
|
248
|
-
}
|
|
243
|
+
this.contracts.forEach((contract) => saveToFile(contract));
|
|
244
|
+
this.scripts.forEach((script) => saveToFile(script));
|
|
249
245
|
await this.projectArtifact.saveToFile(this.artifactsRootDir);
|
|
250
246
|
}
|
|
251
247
|
contractByCodeHash(codeHash) {
|
|
252
|
-
const contract = this.contracts.find((c) => c.artifact.codeHash === codeHash || c.artifact.codeHashDebug == codeHash);
|
|
248
|
+
const contract = [...this.contracts.values()].find((c) => c.artifact.codeHash === codeHash || c.artifact.codeHashDebug == codeHash);
|
|
253
249
|
if (typeof contract === 'undefined') {
|
|
254
250
|
throw new Error(`Unknown code with code hash: ${codeHash}`);
|
|
255
251
|
}
|
|
256
252
|
return contract.artifact;
|
|
257
253
|
}
|
|
258
|
-
static async compile(provider,
|
|
259
|
-
const sourceStr =
|
|
254
|
+
static async compile(provider, sourceInfos, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions) {
|
|
255
|
+
const sourceStr = sourceInfos.map((f) => f.sourceCode).join('\n');
|
|
260
256
|
const result = await provider.contracts.postContractsCompileProject({
|
|
261
257
|
code: sourceStr,
|
|
262
258
|
compilerOptions: compilerOptions
|
|
263
259
|
});
|
|
264
|
-
const contracts =
|
|
265
|
-
const scripts =
|
|
260
|
+
const contracts = new Map();
|
|
261
|
+
const scripts = new Map();
|
|
266
262
|
result.contracts.forEach((contractResult, index) => {
|
|
267
|
-
const
|
|
263
|
+
const sourceInfo = sourceInfos[`${index}`];
|
|
268
264
|
const contract = Contract.fromCompileResult(contractResult);
|
|
269
|
-
contracts.
|
|
265
|
+
contracts.set(contract.name, new Compiled(sourceInfo, contract, contractResult.warnings));
|
|
270
266
|
});
|
|
271
267
|
result.scripts.forEach((scriptResult, index) => {
|
|
272
|
-
const
|
|
268
|
+
const sourceInfo = sourceInfos[index + contracts.size];
|
|
273
269
|
const script = Script.fromCompileResult(scriptResult);
|
|
274
|
-
scripts.
|
|
270
|
+
scripts.set(script.name, new Compiled(sourceInfo, script, scriptResult.warnings));
|
|
275
271
|
});
|
|
276
|
-
const projectArtifact = Project.buildProjectArtifact(
|
|
277
|
-
const project = new Project(contractsRootDir, artifactsRootDir,
|
|
272
|
+
const projectArtifact = Project.buildProjectArtifact(sourceInfos, contracts, scripts, compilerOptions);
|
|
273
|
+
const project = new Project(contractsRootDir, artifactsRootDir, sourceInfos, contracts, scripts, errorOnWarnings, projectArtifact);
|
|
278
274
|
await project.saveArtifactsToFile();
|
|
279
275
|
return project;
|
|
280
276
|
}
|
|
281
|
-
static async loadArtifacts(provider,
|
|
277
|
+
static async loadArtifacts(provider, sourceInfos, projectArtifact, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions) {
|
|
282
278
|
try {
|
|
283
|
-
const contracts =
|
|
284
|
-
const scripts =
|
|
285
|
-
for (const
|
|
286
|
-
const info = projectArtifact.infos.get(
|
|
279
|
+
const contracts = new Map();
|
|
280
|
+
const scripts = new Map();
|
|
281
|
+
for (const sourceInfo of sourceInfos) {
|
|
282
|
+
const info = projectArtifact.infos.get(sourceInfo.name);
|
|
287
283
|
if (typeof info === 'undefined') {
|
|
288
|
-
throw Error(`Unable to find project info for ${
|
|
284
|
+
throw Error(`Unable to find project info for ${sourceInfo.name}, please rebuild the project`);
|
|
289
285
|
}
|
|
290
286
|
const warnings = info.warnings;
|
|
291
|
-
const artifactDir =
|
|
292
|
-
if (
|
|
287
|
+
const artifactDir = sourceInfo.getArtifactPath(artifactsRootDir);
|
|
288
|
+
if (sourceInfo.type === SourceKind.Contract) {
|
|
293
289
|
const artifact = await Contract.fromArtifactFile(artifactDir, info.bytecodeDebugPatch, info.codeHashDebug);
|
|
294
|
-
contracts.
|
|
290
|
+
contracts.set(artifact.name, new Compiled(sourceInfo, artifact, warnings));
|
|
295
291
|
}
|
|
296
|
-
else if (
|
|
292
|
+
else if (sourceInfo.type === SourceKind.Script) {
|
|
297
293
|
const artifact = await Script.fromArtifactFile(artifactDir, info.bytecodeDebugPatch);
|
|
298
|
-
scripts.
|
|
294
|
+
scripts.set(artifact.name, new Compiled(sourceInfo, artifact, warnings));
|
|
299
295
|
}
|
|
300
296
|
}
|
|
301
|
-
return new Project(contractsRootDir, artifactsRootDir,
|
|
297
|
+
return new Project(contractsRootDir, artifactsRootDir, sourceInfos, contracts, scripts, errorOnWarnings, projectArtifact);
|
|
302
298
|
}
|
|
303
299
|
catch (error) {
|
|
304
300
|
console.log(`Failed to load artifacts, error: ${error}, try to re-compile contracts...`);
|
|
305
|
-
return Project.compile(provider,
|
|
301
|
+
return Project.compile(provider, sourceInfos, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions);
|
|
306
302
|
}
|
|
307
303
|
}
|
|
308
|
-
static async loadSourceFile(dirPath, filename) {
|
|
309
|
-
const contractPath = dirPath
|
|
304
|
+
static async loadSourceFile(contractsRootDir, dirPath, filename) {
|
|
305
|
+
const contractPath = path.join(dirPath, filename);
|
|
306
|
+
const contractRelativePath = path.relative(contractsRootDir, contractPath);
|
|
310
307
|
if (!filename.endsWith('.ral')) {
|
|
311
308
|
throw new Error(`Invalid filename: ${contractPath}, smart contract file name should end with ".ral"`);
|
|
312
309
|
}
|
|
313
310
|
const sourceBuffer = await fs_2.promises.readFile(contractPath);
|
|
314
311
|
const sourceStr = sourceBuffer.toString();
|
|
315
|
-
const
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
312
|
+
const sourceInfos = [];
|
|
313
|
+
for (const matcher of this.matchers) {
|
|
314
|
+
const results = sourceStr.matchAll(matcher.matcher);
|
|
315
|
+
for (const result of results) {
|
|
316
|
+
const sourceInfo = await SourceInfo.from(matcher.type, result[1], sourceStr, contractRelativePath);
|
|
317
|
+
sourceInfos.push(sourceInfo);
|
|
318
|
+
}
|
|
322
319
|
}
|
|
323
|
-
|
|
324
|
-
const type = this.matchers[`${matcherIndex}`].type;
|
|
325
|
-
return SourceFile.from(type, sourceStr, contractPath);
|
|
320
|
+
return sourceInfos;
|
|
326
321
|
}
|
|
327
322
|
static async loadSourceFiles(contractsRootDir) {
|
|
328
323
|
const loadDir = async function (dirPath, results) {
|
|
329
324
|
const dirents = await fs_2.promises.readdir(dirPath, { withFileTypes: true });
|
|
330
325
|
for (const dirent of dirents) {
|
|
331
326
|
if (dirent.isFile()) {
|
|
332
|
-
const
|
|
333
|
-
results.push(
|
|
327
|
+
const sourceInfos = await Project.loadSourceFile(contractsRootDir, dirPath, dirent.name);
|
|
328
|
+
results.push(...sourceInfos);
|
|
334
329
|
}
|
|
335
330
|
else {
|
|
336
|
-
const newPath = dirPath
|
|
331
|
+
const newPath = path.join(dirPath, dirent.name);
|
|
337
332
|
await loadDir(newPath, results);
|
|
338
333
|
}
|
|
339
334
|
}
|
|
340
335
|
};
|
|
341
|
-
const
|
|
342
|
-
await loadDir(contractsRootDir,
|
|
343
|
-
const contractAndScriptSize =
|
|
344
|
-
if (
|
|
336
|
+
const sourceInfos = [];
|
|
337
|
+
await loadDir(contractsRootDir, sourceInfos);
|
|
338
|
+
const contractAndScriptSize = sourceInfos.filter((f) => f.type === SourceKind.Contract || f.type === SourceKind.Script).length;
|
|
339
|
+
if (sourceInfos.length === 0 || contractAndScriptSize === 0) {
|
|
345
340
|
throw new Error('Project have no source files');
|
|
346
341
|
}
|
|
347
|
-
return
|
|
342
|
+
return sourceInfos.sort((a, b) => a.type - b.type);
|
|
348
343
|
}
|
|
349
344
|
static async build(compilerOptionsPartial = {}, contractsRootDir = Project.DEFAULT_CONTRACTS_DIR, artifactsRootDir = Project.DEFAULT_ARTIFACTS_DIR) {
|
|
350
345
|
const provider = (0, global_1.getCurrentNodeProvider)();
|
|
@@ -362,10 +357,10 @@ class Project {
|
|
|
362
357
|
}
|
|
363
358
|
}
|
|
364
359
|
exports.Project = Project;
|
|
365
|
-
Project.abstractContractMatcher = new TypedMatcher('^Abstract Contract [A-Z][a-zA-Z0-9]*',
|
|
366
|
-
Project.contractMatcher = new TypedMatcher('^Contract [A-Z][a-zA-Z0-9]*',
|
|
367
|
-
Project.interfaceMatcher = new TypedMatcher('^Interface [A-Z][a-zA-Z0-9]* \\{',
|
|
368
|
-
Project.scriptMatcher = new TypedMatcher('^TxScript [A-Z][a-zA-Z0-9]*',
|
|
360
|
+
Project.abstractContractMatcher = new TypedMatcher('^Abstract Contract ([A-Z][a-zA-Z0-9]*)', SourceKind.AbstractContract);
|
|
361
|
+
Project.contractMatcher = new TypedMatcher('^Contract ([A-Z][a-zA-Z0-9]*)', SourceKind.Contract);
|
|
362
|
+
Project.interfaceMatcher = new TypedMatcher('^Interface ([A-Z][a-zA-Z0-9]*) \\{', SourceKind.Interface);
|
|
363
|
+
Project.scriptMatcher = new TypedMatcher('^TxScript ([A-Z][a-zA-Z0-9]*)', SourceKind.Script);
|
|
369
364
|
Project.matchers = [
|
|
370
365
|
Project.abstractContractMatcher,
|
|
371
366
|
Project.contractMatcher,
|
|
@@ -591,7 +586,7 @@ class Contract extends Artifact {
|
|
|
591
586
|
async txParamsForDeployment(signer, params) {
|
|
592
587
|
const bytecode = this.buildByteCodeToDeploy(params.initialFields ? params.initialFields : {});
|
|
593
588
|
const signerParams = {
|
|
594
|
-
signerAddress:
|
|
589
|
+
signerAddress: await signer.getSelectedAddress(),
|
|
595
590
|
bytecode: bytecode,
|
|
596
591
|
initialAttoAlphAmount: params.initialAttoAlphAmount,
|
|
597
592
|
issueTokenAmount: params.issueTokenAmount,
|
|
@@ -658,7 +653,7 @@ class Script extends Artifact {
|
|
|
658
653
|
}
|
|
659
654
|
async txParamsForExecution(signer, params) {
|
|
660
655
|
const signerParams = {
|
|
661
|
-
signerAddress:
|
|
656
|
+
signerAddress: await signer.getSelectedAddress(),
|
|
662
657
|
bytecode: this.buildByteCodeToDeploy(params.initialFields ? params.initialFields : {}),
|
|
663
658
|
attoAlphAmount: params.attoAlphAmount,
|
|
664
659
|
tokens: params.tokens,
|
package/dist/src/signer/index.js
CHANGED
|
@@ -32,3 +32,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
32
32
|
};
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
34
|
__exportStar(require("./signer"), exports);
|
|
35
|
+
__exportStar(require("./types"), exports);
|
|
36
|
+
__exportStar(require("./tx-builder"), exports);
|
|
@@ -1,100 +1,11 @@
|
|
|
1
|
-
import { ExplorerProvider, NodeProvider
|
|
1
|
+
import { ExplorerProvider, NodeProvider } from '../api';
|
|
2
2
|
import { node } from '../api';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
address: string;
|
|
6
|
-
group: number;
|
|
7
|
-
publicKey: string;
|
|
8
|
-
}
|
|
9
|
-
export declare type SignerAddress = {
|
|
10
|
-
signerAddress: string;
|
|
11
|
-
};
|
|
12
|
-
export interface SignTransferTxParams {
|
|
13
|
-
signerAddress: string;
|
|
14
|
-
destinations: Destination[];
|
|
15
|
-
utxos?: OutputRef[];
|
|
16
|
-
gasAmount?: number;
|
|
17
|
-
gasPrice?: Number256;
|
|
18
|
-
}
|
|
19
|
-
export interface SignTransferTxResult {
|
|
20
|
-
fromGroup: number;
|
|
21
|
-
toGroup: number;
|
|
22
|
-
unsignedTx: string;
|
|
23
|
-
txId: string;
|
|
24
|
-
signature: string;
|
|
25
|
-
gasAmount: number;
|
|
26
|
-
gasPrice: Number256;
|
|
27
|
-
}
|
|
28
|
-
export interface SignDeployContractTxParams {
|
|
29
|
-
signerAddress: string;
|
|
30
|
-
bytecode: string;
|
|
31
|
-
initialAttoAlphAmount?: Number256;
|
|
32
|
-
initialTokenAmounts?: Token[];
|
|
33
|
-
issueTokenAmount?: Number256;
|
|
34
|
-
gasAmount?: number;
|
|
35
|
-
gasPrice?: Number256;
|
|
36
|
-
}
|
|
37
|
-
export interface SignDeployContractTxResult {
|
|
38
|
-
fromGroup: number;
|
|
39
|
-
toGroup: number;
|
|
40
|
-
unsignedTx: string;
|
|
41
|
-
txId: string;
|
|
42
|
-
signature: string;
|
|
43
|
-
contractId: string;
|
|
44
|
-
contractAddress: string;
|
|
45
|
-
gasAmount: number;
|
|
46
|
-
gasPrice: Number256;
|
|
47
|
-
}
|
|
48
|
-
export interface SignExecuteScriptTxParams {
|
|
49
|
-
signerAddress: string;
|
|
50
|
-
bytecode: string;
|
|
51
|
-
attoAlphAmount?: Number256;
|
|
52
|
-
tokens?: Token[];
|
|
53
|
-
gasAmount?: number;
|
|
54
|
-
gasPrice?: Number256;
|
|
55
|
-
}
|
|
56
|
-
export interface SignExecuteScriptTxResult {
|
|
57
|
-
fromGroup: number;
|
|
58
|
-
toGroup: number;
|
|
59
|
-
unsignedTx: string;
|
|
60
|
-
txId: string;
|
|
61
|
-
signature: string;
|
|
62
|
-
gasAmount: number;
|
|
63
|
-
gasPrice: Number256;
|
|
64
|
-
}
|
|
65
|
-
export interface SignUnsignedTxParams {
|
|
66
|
-
signerAddress: string;
|
|
67
|
-
unsignedTx: string;
|
|
68
|
-
}
|
|
69
|
-
export interface SignUnsignedTxResult {
|
|
70
|
-
fromGroup: number;
|
|
71
|
-
toGroup: number;
|
|
72
|
-
unsignedTx: string;
|
|
73
|
-
txId: string;
|
|
74
|
-
signature: string;
|
|
75
|
-
gasAmount: number;
|
|
76
|
-
gasPrice: Number256;
|
|
77
|
-
}
|
|
78
|
-
export interface SignMessageParams {
|
|
79
|
-
signerAddress: string;
|
|
80
|
-
message: string;
|
|
81
|
-
}
|
|
82
|
-
export interface SignMessageResult {
|
|
83
|
-
signature: string;
|
|
84
|
-
}
|
|
85
|
-
export interface SubmitTransactionParams {
|
|
86
|
-
unsignedTx: string;
|
|
87
|
-
signature: string;
|
|
88
|
-
}
|
|
89
|
-
export interface SubmissionResult {
|
|
90
|
-
txId: string;
|
|
91
|
-
fromGroup: number;
|
|
92
|
-
toGroup: number;
|
|
93
|
-
}
|
|
3
|
+
import { Account, Address, EnableOptionsBase, Destination, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignMessageParams, SignMessageResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, SubmissionResult, SubmitTransactionParams, ExtSignTransferTxParams, ExtSignDeployContractTxParams, ExtSignExecuteScriptTxParams, ExtSignUnsignedTxParams, ExtSignMessageParams } from './types';
|
|
4
|
+
import { TransactionBuilder } from './tx-builder';
|
|
94
5
|
export interface SignerProvider {
|
|
95
6
|
get nodeProvider(): NodeProvider | undefined;
|
|
96
7
|
get explorerProvider(): ExplorerProvider | undefined;
|
|
97
|
-
|
|
8
|
+
getSelectedAddress(): Promise<Address>;
|
|
98
9
|
signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
|
|
99
10
|
signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
|
|
100
11
|
signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
|
|
@@ -102,41 +13,53 @@ export interface SignerProvider {
|
|
|
102
13
|
signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
103
14
|
signMessage(params: SignMessageParams): Promise<SignMessageResult>;
|
|
104
15
|
}
|
|
105
|
-
export
|
|
106
|
-
|
|
16
|
+
export interface InteractiveSignerProvider<EnableOptions extends EnableOptionsBase = EnableOptionsBase> extends SignerProvider {
|
|
17
|
+
enable(opt?: EnableOptions): Promise<Address>;
|
|
18
|
+
disconnect(): Promise<void>;
|
|
19
|
+
signAndSubmitTransferTx(params: ExtSignTransferTxParams): Promise<SignTransferTxResult>;
|
|
20
|
+
signAndSubmitDeployContractTx(params: ExtSignDeployContractTxParams): Promise<SignDeployContractTxResult>;
|
|
21
|
+
signAndSubmitExecuteScriptTx(params: ExtSignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
|
|
22
|
+
signAndSubmitUnsignedTx(params: ExtSignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
23
|
+
signUnsignedTx(params: ExtSignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
24
|
+
signMessage(params: ExtSignMessageParams): Promise<SignMessageResult>;
|
|
25
|
+
}
|
|
26
|
+
export declare abstract class SignerProviderSimple extends TransactionBuilder implements SignerProvider {
|
|
107
27
|
abstract get explorerProvider(): ExplorerProvider | undefined;
|
|
108
28
|
abstract getSelectedAccount(): Promise<Account>;
|
|
109
|
-
|
|
29
|
+
getSelectedAddress(): Promise<Address>;
|
|
110
30
|
submitTransaction(params: SubmitTransactionParams): Promise<SubmissionResult>;
|
|
111
31
|
signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
|
|
112
32
|
signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
|
|
113
33
|
signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
|
|
114
34
|
signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
35
|
+
protected abstract getPublicKey(address: string): Promise<string>;
|
|
115
36
|
private usePublicKey;
|
|
116
37
|
signTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
|
|
117
|
-
buildTransferTx(params: SignTransferTxParams): Promise<
|
|
38
|
+
buildTransferTx(params: SignTransferTxParams): Promise<Omit<SignTransferTxResult, 'signature'>>;
|
|
118
39
|
signDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
|
|
119
|
-
|
|
40
|
+
buildDeployContractTx(params: SignDeployContractTxParams): Promise<Omit<SignDeployContractTxResult, 'signature'>>;
|
|
120
41
|
signExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
|
|
121
|
-
|
|
42
|
+
buildExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<Omit<SignExecuteScriptTxResult, 'signature'>>;
|
|
122
43
|
signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
123
44
|
signMessage(params: SignMessageParams): Promise<SignMessageResult>;
|
|
124
45
|
abstract signRaw(signerAddress: string, hexString: string): Promise<string>;
|
|
125
46
|
}
|
|
126
47
|
export declare abstract class SignerProviderWithMultipleAccounts extends SignerProviderSimple {
|
|
48
|
+
abstract setSelectedAddress(address: string): Promise<void>;
|
|
127
49
|
abstract getAccounts(): Promise<Account[]>;
|
|
128
50
|
getAccount(signerAddress: string): Promise<Account>;
|
|
129
|
-
|
|
51
|
+
getPublicKey(signerAddress: string): Promise<string>;
|
|
52
|
+
}
|
|
53
|
+
export declare abstract class SignerProviderWithCachedAccounts<T extends Account> extends SignerProviderWithMultipleAccounts {
|
|
54
|
+
private _selectedAccount;
|
|
55
|
+
protected readonly _accounts: Map<string, T>;
|
|
56
|
+
getSelectedAccount(): Promise<T>;
|
|
57
|
+
setSelectedAddress(address: string): Promise<void>;
|
|
58
|
+
getAccounts(): Promise<T[]>;
|
|
59
|
+
getAccount(address: string): Promise<T>;
|
|
130
60
|
}
|
|
131
61
|
export declare function verifyHexString(hexString: string, publicKey: string, signature: string): boolean;
|
|
132
62
|
export declare function verifySignedMessage(message: string, publicKey: string, signature: string): boolean;
|
|
133
|
-
export interface Destination {
|
|
134
|
-
address: string;
|
|
135
|
-
attoAlphAmount: Number256;
|
|
136
|
-
tokens?: Token[];
|
|
137
|
-
lockTime?: number;
|
|
138
|
-
message?: string;
|
|
139
|
-
}
|
|
140
63
|
export declare function toApiDestination(data: Destination): node.Destination;
|
|
141
64
|
export declare function toApiDestinations(data: Destination[]): node.Destination[];
|
|
142
65
|
export declare function fromApiDestination(data: node.Destination): Destination;
|