Removed dead files.
This commit is contained in:
parent
f733fac875
commit
27b3af0a7b
@ -1 +0,0 @@
|
||||
export declare const platform = "browser";
|
@ -1,2 +0,0 @@
|
||||
"use strict";
|
||||
export const platform = "browser";
|
1
packages/ethers/lib.esm/platform.d.ts
vendored
1
packages/ethers/lib.esm/platform.d.ts
vendored
@ -1 +0,0 @@
|
||||
export declare const platform = "node";
|
@ -1,2 +0,0 @@
|
||||
"use strict";
|
||||
export const platform = "node";
|
1
packages/ethers/lib/browser-platform.d.ts
vendored
1
packages/ethers/lib/browser-platform.d.ts
vendored
@ -1 +0,0 @@
|
||||
export declare const platform = "browser";
|
@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.platform = "browser";
|
1
packages/ethers/lib/platform.d.ts
vendored
1
packages/ethers/lib/platform.d.ts
vendored
@ -1 +0,0 @@
|
||||
export declare const platform = "node";
|
@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.platform = "node";
|
10
packages/experimental/lib.esm/eip-provider.d.ts
vendored
10
packages/experimental/lib.esm/eip-provider.d.ts
vendored
@ -1,10 +0,0 @@
|
||||
import { ethers } from "ethers";
|
||||
export interface Eip1193Provider {
|
||||
send: (message: string, params?: Array<any>) => Promise<any>;
|
||||
on(eventName: string, listener: (...args: Array<any>) => void): this;
|
||||
}
|
||||
export declare class EipWrappedProvider extends ethers.providers.JsonRpcProvider {
|
||||
readonly provider: Eip1193Provider;
|
||||
constructor(provider: Eip1193Provider, network?: ethers.providers.Networkish);
|
||||
send(method: string, params: any): Promise<any>;
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
"use strict";
|
||||
import { ethers } from "ethers";
|
||||
import { version } from "./_version";
|
||||
const logger = new ethers.utils.Logger(version);
|
||||
export class EipWrappedProvider extends ethers.providers.JsonRpcProvider {
|
||||
constructor(provider, network) {
|
||||
logger.checkNew(new.target, EipWrappedProvider);
|
||||
super("eip1193:/\/", network);
|
||||
ethers.utils.defineReadOnly(this, "provider", provider);
|
||||
}
|
||||
send(method, params) {
|
||||
return this.provider.send(method, params);
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
import { ethers } from "ethers";
|
||||
export declare type RetryOptions = {
|
||||
timeout?: number;
|
||||
floor?: number;
|
||||
ceiling?: number;
|
||||
interval?: number;
|
||||
retryLimit?: number;
|
||||
};
|
||||
export declare class RetryProvider extends ethers.providers.BaseProvider {
|
||||
readonly provider: ethers.providers.BaseProvider;
|
||||
readonly options: RetryOptions;
|
||||
constructor(provider: ethers.providers.BaseProvider, options?: RetryOptions);
|
||||
perform(method: string, params: any): Promise<any>;
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
"use strict";
|
||||
// RetryProvider
|
||||
//
|
||||
// Wraps an existing Provider to provide retry logic.
|
||||
//
|
||||
// See: https://github.com/ethers-io/ethers.js/issues/427
|
||||
import { ethers } from "ethers";
|
||||
import { poll } from "@ethersproject/web";
|
||||
import { version } from "./_version";
|
||||
const logger = new ethers.utils.Logger(version);
|
||||
export class RetryProvider extends ethers.providers.BaseProvider {
|
||||
constructor(provider, options) {
|
||||
logger.checkNew(new.target, RetryProvider);
|
||||
super(provider.getNetwork());
|
||||
ethers.utils.defineReadOnly(this, "provider", provider);
|
||||
ethers.utils.defineReadOnly(this, "options", options || {});
|
||||
}
|
||||
perform(method, params) {
|
||||
return poll(() => {
|
||||
return this.provider.perform(method, params).then((result) => {
|
||||
return result;
|
||||
}, (error) => {
|
||||
return undefined;
|
||||
});
|
||||
}, this.options);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=retry-provider.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"retry-provider.js","sourceRoot":"","sources":["../src.ts/retry-provider.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,gBAAgB;AAChB,EAAE;AACF,qDAAqD;AACrD,EAAE;AACF,yDAAyD;AAGzD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAmBhD,MAAM,OAAO,aAAc,SAAQ,MAAM,CAAC,SAAS,CAAC,YAAY;IAI5D,YAAY,QAAuC,EAAE,OAAsB;QACvE,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;QAC3C,KAAK,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;QAC7B,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;QACxD,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,IAAI,EAAG,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,CAAC,MAAc,EAAE,MAAW;QAC/B,OAAO,IAAI,CAAC,GAAG,EAAE;YACb,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;gBACzD,OAAO,MAAM,CAAA;YACjB,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;gBACT,OAAO,SAAS,CAAA;YACpB,CAAC,CAAC,CAAC;QACP,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;CACJ"}
|
10
packages/experimental/lib/eip-provider.d.ts
vendored
10
packages/experimental/lib/eip-provider.d.ts
vendored
@ -1,10 +0,0 @@
|
||||
import { ethers } from "ethers";
|
||||
export interface Eip1193Provider {
|
||||
send: (message: string, params?: Array<any>) => Promise<any>;
|
||||
on(eventName: string, listener: (...args: Array<any>) => void): this;
|
||||
}
|
||||
export declare class EipWrappedProvider extends ethers.providers.JsonRpcProvider {
|
||||
readonly provider: Eip1193Provider;
|
||||
constructor(provider: Eip1193Provider, network?: ethers.providers.Networkish);
|
||||
send(method: string, params: any): Promise<any>;
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var ethers_1 = require("ethers");
|
||||
var _version_1 = require("./_version");
|
||||
var logger = new ethers_1.ethers.utils.Logger(_version_1.version);
|
||||
var EipWrappedProvider = /** @class */ (function (_super) {
|
||||
__extends(EipWrappedProvider, _super);
|
||||
function EipWrappedProvider(provider, network) {
|
||||
var _newTarget = this.constructor;
|
||||
var _this = this;
|
||||
logger.checkNew(_newTarget, EipWrappedProvider);
|
||||
_this = _super.call(this, "eip1193:/\/", network) || this;
|
||||
ethers_1.ethers.utils.defineReadOnly(_this, "provider", provider);
|
||||
return _this;
|
||||
}
|
||||
EipWrappedProvider.prototype.send = function (method, params) {
|
||||
return this.provider.send(method, params);
|
||||
};
|
||||
return EipWrappedProvider;
|
||||
}(ethers_1.ethers.providers.JsonRpcProvider));
|
||||
exports.EipWrappedProvider = EipWrappedProvider;
|
14
packages/experimental/lib/retry-provider.d.ts
vendored
14
packages/experimental/lib/retry-provider.d.ts
vendored
@ -1,14 +0,0 @@
|
||||
import { ethers } from "ethers";
|
||||
export declare type RetryOptions = {
|
||||
timeout?: number;
|
||||
floor?: number;
|
||||
ceiling?: number;
|
||||
interval?: number;
|
||||
retryLimit?: number;
|
||||
};
|
||||
export declare class RetryProvider extends ethers.providers.BaseProvider {
|
||||
readonly provider: ethers.providers.BaseProvider;
|
||||
readonly options: RetryOptions;
|
||||
constructor(provider: ethers.providers.BaseProvider, options?: RetryOptions);
|
||||
perform(method: string, params: any): Promise<any>;
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// RetryProvider
|
||||
//
|
||||
// Wraps an existing Provider to provide retry logic.
|
||||
//
|
||||
// See: https://github.com/ethers-io/ethers.js/issues/427
|
||||
var ethers_1 = require("ethers");
|
||||
var web_1 = require("@ethersproject/web");
|
||||
var _version_1 = require("./_version");
|
||||
var logger = new ethers_1.ethers.utils.Logger(_version_1.version);
|
||||
var RetryProvider = /** @class */ (function (_super) {
|
||||
__extends(RetryProvider, _super);
|
||||
function RetryProvider(provider, options) {
|
||||
var _newTarget = this.constructor;
|
||||
var _this = this;
|
||||
logger.checkNew(_newTarget, RetryProvider);
|
||||
_this = _super.call(this, provider.getNetwork()) || this;
|
||||
ethers_1.ethers.utils.defineReadOnly(_this, "provider", provider);
|
||||
ethers_1.ethers.utils.defineReadOnly(_this, "options", options || {});
|
||||
return _this;
|
||||
}
|
||||
RetryProvider.prototype.perform = function (method, params) {
|
||||
var _this = this;
|
||||
return web_1.poll(function () {
|
||||
return _this.provider.perform(method, params).then(function (result) {
|
||||
return result;
|
||||
}, function (error) {
|
||||
return undefined;
|
||||
});
|
||||
}, this.options);
|
||||
};
|
||||
return RetryProvider;
|
||||
}(ethers_1.ethers.providers.BaseProvider));
|
||||
exports.RetryProvider = RetryProvider;
|
||||
//# sourceMappingURL=retry-provider.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"retry-provider.js","sourceRoot":"","sources":["../src.ts/retry-provider.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;AAEb,gBAAgB;AAChB,EAAE;AACF,qDAAqD;AACrD,EAAE;AACF,yDAAyD;AAGzD,iCAAgC;AAChC,0CAA0C;AAE1C,uCAAqC;AAErC,IAAM,MAAM,GAAG,IAAI,eAAM,CAAC,KAAK,CAAC,MAAM,CAAC,kBAAO,CAAC,CAAC;AAmBhD;IAAmC,iCAA6B;IAI5D,uBAAY,QAAuC,EAAE,OAAsB;;QAA3E,iBAKC;QAJG,MAAM,CAAC,QAAQ,aAAa,aAAa,CAAC,CAAC;QAC3C,QAAA,kBAAM,QAAQ,CAAC,UAAU,EAAE,CAAC,SAAC;QAC7B,eAAM,CAAC,KAAK,CAAC,cAAc,CAAC,KAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;QACxD,eAAM,CAAC,KAAK,CAAC,cAAc,CAAC,KAAI,EAAE,SAAS,EAAE,OAAO,IAAI,EAAG,CAAC,CAAC;;IACjE,CAAC;IAED,+BAAO,GAAP,UAAQ,MAAc,EAAE,MAAW;QAAnC,iBAQC;QAPG,OAAO,UAAI,CAAC;YACR,OAAO,KAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,UAAC,MAAM;gBACrD,OAAO,MAAM,CAAA;YACjB,CAAC,EAAE,UAAC,KAAK;gBACL,OAAO,SAAS,CAAA;YACpB,CAAC,CAAC,CAAC;QACP,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;IACL,oBAAC;AAAD,CAAC,AApBD,CAAmC,eAAM,CAAC,SAAS,CAAC,YAAY,GAoB/D;AApBY,sCAAa"}
|
12
packages/providers/lib.esm/eip-provider.d.ts
vendored
12
packages/providers/lib.esm/eip-provider.d.ts
vendored
@ -1,12 +0,0 @@
|
||||
import { Networkish } from "@ethersproject/networks";
|
||||
import { JsonRpcProvider } from "./json-rpc-provider";
|
||||
export interface Eip1193Provider {
|
||||
isMetaMask?: boolean;
|
||||
send: (message: string, params?: Array<any>) => Promise<any>;
|
||||
on(eventName: string, listener: (...args: Array<any>) => void): this;
|
||||
}
|
||||
export declare class EipWrappedProvider extends JsonRpcProvider {
|
||||
readonly provider: Eip1193Provider;
|
||||
constructor(provider: Eip1193Provider, network?: Networkish);
|
||||
send(method: string, params: any): Promise<any>;
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
"use strict";
|
||||
import { defineReadOnly } from "@ethersproject/properties";
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "./_version";
|
||||
const logger = new Logger(version);
|
||||
import { JsonRpcProvider } from "./json-rpc-provider";
|
||||
export class EipWrappedProvider extends JsonRpcProvider {
|
||||
constructor(provider, network) {
|
||||
logger.checkNew(new.target, EipWrappedProvider);
|
||||
// HTTP has a host; IPC has a path.
|
||||
super("eip1193:/\/", network);
|
||||
defineReadOnly(this, "provider", provider);
|
||||
}
|
||||
send(method, params) {
|
||||
// Metamask complains about eth_sign (and on some versions hangs)
|
||||
if (method == "eth_sign" && this.provider.isMetaMask) {
|
||||
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
|
||||
method = "personal_sign";
|
||||
params = [params[1], params[0]];
|
||||
}
|
||||
return this.provider.send(method, params);
|
||||
}
|
||||
}
|
12
packages/providers/lib/eip-provider.d.ts
vendored
12
packages/providers/lib/eip-provider.d.ts
vendored
@ -1,12 +0,0 @@
|
||||
import { Networkish } from "@ethersproject/networks";
|
||||
import { JsonRpcProvider } from "./json-rpc-provider";
|
||||
export interface Eip1193Provider {
|
||||
isMetaMask?: boolean;
|
||||
send: (message: string, params?: Array<any>) => Promise<any>;
|
||||
on(eventName: string, listener: (...args: Array<any>) => void): this;
|
||||
}
|
||||
export declare class EipWrappedProvider extends JsonRpcProvider {
|
||||
readonly provider: Eip1193Provider;
|
||||
constructor(provider: Eip1193Provider, network?: Networkish);
|
||||
send(method: string, params: any): Promise<any>;
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var properties_1 = require("@ethersproject/properties");
|
||||
var logger_1 = require("@ethersproject/logger");
|
||||
var _version_1 = require("./_version");
|
||||
var logger = new logger_1.Logger(_version_1.version);
|
||||
var json_rpc_provider_1 = require("./json-rpc-provider");
|
||||
var EipWrappedProvider = /** @class */ (function (_super) {
|
||||
__extends(EipWrappedProvider, _super);
|
||||
function EipWrappedProvider(provider, network) {
|
||||
var _newTarget = this.constructor;
|
||||
var _this = this;
|
||||
logger.checkNew(_newTarget, EipWrappedProvider);
|
||||
// HTTP has a host; IPC has a path.
|
||||
_this = _super.call(this, "eip1193:/\/", network) || this;
|
||||
properties_1.defineReadOnly(_this, "provider", provider);
|
||||
return _this;
|
||||
}
|
||||
EipWrappedProvider.prototype.send = function (method, params) {
|
||||
// Metamask complains about eth_sign (and on some versions hangs)
|
||||
if (method == "eth_sign" && this.provider.isMetaMask) {
|
||||
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
|
||||
method = "personal_sign";
|
||||
params = [params[1], params[0]];
|
||||
}
|
||||
return this.provider.send(method, params);
|
||||
};
|
||||
return EipWrappedProvider;
|
||||
}(json_rpc_provider_1.JsonRpcProvider));
|
||||
exports.EipWrappedProvider = EipWrappedProvider;
|
@ -1,523 +0,0 @@
|
||||
"use strict";
|
||||
//let web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8549'));
|
||||
//import { compile as _compile } from "solc";
|
||||
import { solc } from "@ethersproject/cli";
|
||||
import { randomHexString, randomNumber } from "..";
|
||||
import { BN, keccak256, toChecksumAddress } from "ethereumjs-util";
|
||||
function hasPrefix(str, prefix) {
|
||||
return (str.substring(0, prefix.length) === prefix);
|
||||
}
|
||||
function repeat(str, count) {
|
||||
let result = "";
|
||||
for (let i = 0; i < count; i++) {
|
||||
result += str;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function indent(tabs) {
|
||||
let result = '';
|
||||
while (result.length < 4 * tabs) {
|
||||
result += " ";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function getStructName(base) {
|
||||
return "Struct" + keccak256(base).slice(0, 4).toString("hex");
|
||||
}
|
||||
class Code {
|
||||
constructor() {
|
||||
this.depth = 0;
|
||||
this.lines = [];
|
||||
}
|
||||
get code() {
|
||||
return this.lines.join("\n"); //.replace(/ +\n/g, "\n").replace(/(\}\n\n+)/g, "}\n");
|
||||
}
|
||||
comment(line) {
|
||||
this.add("");
|
||||
this.add("/" + "/ " + line);
|
||||
}
|
||||
add(line) {
|
||||
let open = (line.trim().substring(line.trim().length - 1) === "{");
|
||||
let close = line.trim()[0] === "}";
|
||||
if (close) {
|
||||
this.depth--;
|
||||
}
|
||||
this.lines.push(indent(this.depth) + line);
|
||||
//if (close) { this.lines.push(""); }
|
||||
if (open) {
|
||||
this.depth++;
|
||||
}
|
||||
}
|
||||
}
|
||||
let chars = [];
|
||||
function addChars(start, length) {
|
||||
for (let i = start; i < start + length; i++) {
|
||||
chars.push(String.fromCharCode(i));
|
||||
}
|
||||
}
|
||||
addChars(48, 10);
|
||||
addChars(65, 26);
|
||||
// Returns the functions required to generate code for a specific parameter type and value
|
||||
function getGenCode(testData) {
|
||||
let type = testData.type;
|
||||
let value = (testData.value != null) ? testData.value : "__crash__";
|
||||
let isArray = type.match(/^(.*)(\[[0-9]*\])$/);
|
||||
if (isArray) {
|
||||
let base = isArray[1];
|
||||
let suffix = isArray[2];
|
||||
let isDynamic = (isArray[2] === "[]");
|
||||
return {
|
||||
assign: (name, code) => {
|
||||
if (isDynamic) {
|
||||
//let child = getGenCode({ type: base });
|
||||
//let decl = child.decl(name).split(" ");
|
||||
let struct = base;
|
||||
if (type.substring(0, 5) === "tuple") {
|
||||
struct = getStructName(base);
|
||||
}
|
||||
code.add(name + " = new " + struct + "[](" + String(value.length) + ");");
|
||||
}
|
||||
value.forEach((value, index) => {
|
||||
console.log("SSS", base, value);
|
||||
let child = getGenCode({ type: base, value: value });
|
||||
child.assign(name + "[" + String(index) + "]", code);
|
||||
});
|
||||
},
|
||||
decl: (name) => {
|
||||
let child = getGenCode({ type: isArray[1] });
|
||||
// Inject the array suffix to the type and add memory location
|
||||
// - uint256 p0 => uint256[] memory p0
|
||||
// - bytes memory p0 => bytes[] memory p0
|
||||
let result = child.decl(name).split(" ");
|
||||
result[0] = result[0] + suffix;
|
||||
if (result[1] !== "memory") {
|
||||
result.splice(1, 0, "memory");
|
||||
}
|
||||
return result.join(" ");
|
||||
},
|
||||
structs: (code) => {
|
||||
let child = getGenCode({ type: isArray[1] });
|
||||
child.structs(code);
|
||||
}
|
||||
};
|
||||
}
|
||||
let isTuple = type.match(/^tuple\((.*)\)$/);
|
||||
if (isTuple) {
|
||||
let children = [];
|
||||
// Split up the child types
|
||||
let accum = "";
|
||||
let balance = 0;
|
||||
let types = isTuple[1];
|
||||
for (let i = 0; i < types.length; i++) {
|
||||
let c = types[i];
|
||||
if (c === "(") {
|
||||
balance++;
|
||||
accum += c;
|
||||
}
|
||||
else if (c === ")") {
|
||||
balance--;
|
||||
accum += c;
|
||||
}
|
||||
else if (c === ",") {
|
||||
if (balance === 0) {
|
||||
children.push(accum);
|
||||
accum = "";
|
||||
}
|
||||
else {
|
||||
accum += c;
|
||||
}
|
||||
}
|
||||
else {
|
||||
accum += c;
|
||||
}
|
||||
}
|
||||
if (accum) {
|
||||
children.push(accum);
|
||||
}
|
||||
return {
|
||||
assign: (name, code) => {
|
||||
children.forEach((child, index) => {
|
||||
console.log("TT", child, value[index]);
|
||||
getGenCode({
|
||||
type: child,
|
||||
value: value[index]
|
||||
}).assign(name + ".m" + String(index), code);
|
||||
});
|
||||
},
|
||||
decl: (name) => {
|
||||
return (getStructName(type) + " memory " + name);
|
||||
},
|
||||
structs: (code) => {
|
||||
// Include any dependency Structs first
|
||||
children.forEach((child) => {
|
||||
getGenCode({ type: child }).structs(code);
|
||||
});
|
||||
// Add this struct
|
||||
code.add("struct " + getStructName(type) + " {");
|
||||
children.forEach((child, index) => {
|
||||
let decl = getGenCode({
|
||||
type: child
|
||||
}).decl("m" + String(index)).replace(" memory ", " ");
|
||||
code.add(decl + ";");
|
||||
});
|
||||
code.add("}");
|
||||
}
|
||||
};
|
||||
}
|
||||
let isFixedBytes = type.match(/^bytes([0-9]+)$/);
|
||||
let isNumber = type.match(/^(u?)int([0-9]*)$/);
|
||||
let isFixedNumber = type.match(/^(u?)fixed(([0-9]+)x([0-9]+))?$/);
|
||||
if (type === "address" || type === "bool" || isNumber || isFixedNumber || isFixedBytes) {
|
||||
return {
|
||||
assign: (name, code) => {
|
||||
if (type === "boolean") {
|
||||
code.add(name + " = " + (value ? "true" : "false") + ";");
|
||||
}
|
||||
else if (isFixedBytes) {
|
||||
code.add(name + " = hex\"" + value.substring(2) + "\";");
|
||||
}
|
||||
else {
|
||||
code.add(name + " = " + value + ";");
|
||||
}
|
||||
},
|
||||
decl: (name) => {
|
||||
return (type + " " + name);
|
||||
},
|
||||
structs: (code) => { }
|
||||
};
|
||||
}
|
||||
if (type === "string") {
|
||||
return {
|
||||
assign: (name, code) => {
|
||||
code.add(name + " = " + JSON.stringify(value) + ";");
|
||||
},
|
||||
decl: (name) => {
|
||||
return ("string memory " + name);
|
||||
},
|
||||
structs: (code) => { }
|
||||
};
|
||||
}
|
||||
if (type === "bytes") {
|
||||
let valueBytes = Buffer.from(value.substring(2), "hex");
|
||||
return {
|
||||
assign: (name, code) => {
|
||||
code.add("{");
|
||||
code.add("bytes memory temp = new bytes(" + valueBytes.length + ");");
|
||||
code.add(name + " = temp;");
|
||||
code.add("assembly {");
|
||||
// Store the length
|
||||
code.add("mstore(temp, " + valueBytes.length + ")");
|
||||
// Store each byte
|
||||
for (let i = 0; i < valueBytes.length; i++) {
|
||||
code.add("mstore8(add(temp, " + (32 + i) + "), " + valueBytes[i] + ")");
|
||||
}
|
||||
code.add("}");
|
||||
code.add("}");
|
||||
},
|
||||
decl: (name) => {
|
||||
return ("bytes memory " + name);
|
||||
},
|
||||
structs: (code) => { }
|
||||
};
|
||||
}
|
||||
throw new Error("Could not produce GenCode: " + type);
|
||||
return null;
|
||||
}
|
||||
// Generates a random type and value for the type
|
||||
function generateTest(seed) {
|
||||
let basetype = randomNumber(seed + "-type", 0, 10);
|
||||
switch (basetype) {
|
||||
// Address
|
||||
case 0:
|
||||
return (seed) => {
|
||||
let value = toChecksumAddress(randomHexString(seed + "-value", 20));
|
||||
return {
|
||||
type: "address",
|
||||
value: value
|
||||
};
|
||||
};
|
||||
// Boolean
|
||||
case 1:
|
||||
return (seed) => {
|
||||
let value = (randomNumber(seed + "-value", 0, 2) ? true : false);
|
||||
return {
|
||||
type: "bool",
|
||||
value: value
|
||||
};
|
||||
};
|
||||
// Number
|
||||
case 2: {
|
||||
let signed = randomNumber(seed + "-signed", 0, 2);
|
||||
let width = randomNumber(seed + "-width", 0, 33) * 8;
|
||||
let type = (signed ? "" : "u") + "int";
|
||||
// Allow base int and uint
|
||||
if (width) {
|
||||
type += String(width);
|
||||
}
|
||||
else {
|
||||
width = 256;
|
||||
}
|
||||
return (seed) => {
|
||||
let hex = randomHexString(seed + "-value", width / 8).substring(2);
|
||||
if (signed) {
|
||||
// Sign bit set (we don't bother with 2's compliment
|
||||
let msb = parseInt(hex[0], 16);
|
||||
if (msb >= 8) {
|
||||
hex = "-" + String(msb & 0x7) + hex.substring(1);
|
||||
}
|
||||
}
|
||||
let value = (new BN(hex, 16)).toString();
|
||||
return {
|
||||
type: type,
|
||||
value: value
|
||||
};
|
||||
};
|
||||
}
|
||||
// Fixed
|
||||
case 3: {
|
||||
// Fixed Point values are not supported yet
|
||||
return generateTest(seed + "-next");
|
||||
let signed = randomNumber(seed + "-signed", 0, 2);
|
||||
let width = randomNumber(seed + "-width", 0, 33) * 8;
|
||||
let decimals = 0;
|
||||
let maxDecimals = (new BN(repeat("7f", ((width === 0) ? 32 : (width / 8))), 16)).toString().length - 1;
|
||||
let attempt = 0;
|
||||
while (true) {
|
||||
decimals = randomNumber(seed + "-decimals" + String(attempt), 0, 80);
|
||||
if (decimals < maxDecimals) {
|
||||
break;
|
||||
}
|
||||
attempt++;
|
||||
}
|
||||
let type = (signed ? "" : "u") + "fixed";
|
||||
// Allow base int and uint
|
||||
if (width) {
|
||||
type += String(width) + "x" + String(decimals);
|
||||
}
|
||||
else {
|
||||
width = 128;
|
||||
decimals = 18;
|
||||
}
|
||||
return (seed) => {
|
||||
let hex = randomHexString(seed + "-value", width / 8).substring(2);
|
||||
// Use the top bit to indicate negative values
|
||||
let negative = false;
|
||||
if (signed) {
|
||||
// Sign bit set (we don't bother with 2's compliment
|
||||
let msb = parseInt(hex[0], 16);
|
||||
if (msb >= 8) {
|
||||
hex = String(msb & 0x7) + hex.substring(1);
|
||||
negative = true;
|
||||
}
|
||||
}
|
||||
// Zero-pad the value so we get at least 1 whole digit
|
||||
let dec = (new BN(hex, 16)).toString();
|
||||
while (dec.length < decimals + 1) {
|
||||
dec = "0" + dec;
|
||||
}
|
||||
// Split the decimals with the decimal point
|
||||
let split = dec.length - decimals;
|
||||
let value = dec.substring(0, split) + "." + dec.substring(split);
|
||||
if (negative) {
|
||||
value = "-" + value;
|
||||
}
|
||||
// Prevent ending in a decimal (e.g. "45."
|
||||
if (value.substring(value.length - 1) === ".") {
|
||||
value = value.substring(0, value.length - 1);
|
||||
}
|
||||
return {
|
||||
type: type,
|
||||
value: value
|
||||
};
|
||||
};
|
||||
}
|
||||
// BytesXX
|
||||
case 4: {
|
||||
let length = randomNumber(seed + "-length", 1, 33);
|
||||
let type = "bytes" + String(length);
|
||||
return (seed) => {
|
||||
let value = randomHexString(seed + "-value", length);
|
||||
return {
|
||||
type: type,
|
||||
value: value
|
||||
};
|
||||
};
|
||||
}
|
||||
// String
|
||||
case 5:
|
||||
return (seed) => {
|
||||
let length = randomNumber(seed + "-length", 0, 36);
|
||||
let value = "";
|
||||
while (value.length < length) {
|
||||
value += chars[randomNumber(seed + "-value" + String(value.length), 0, chars.length)];
|
||||
}
|
||||
return {
|
||||
type: "string",
|
||||
value: value
|
||||
};
|
||||
};
|
||||
// Bytes
|
||||
case 6:
|
||||
return (seed) => {
|
||||
let length = randomNumber(seed + "-length", 0, 12); // @TODO: increase this
|
||||
let value = randomHexString(seed + "-value", length);
|
||||
//let valueBytes = Buffer.from(value.substring(2), "hex");
|
||||
return {
|
||||
type: "bytes",
|
||||
value: value
|
||||
};
|
||||
};
|
||||
// Fixed-Length Array (e.g. address[4])
|
||||
case 7:
|
||||
// Falls-through
|
||||
// Dynamic-Length Array (e.g. address[])
|
||||
case 8: {
|
||||
let dynamic = (basetype === 8);
|
||||
let subType = generateTest(seed + "-subtype");
|
||||
let length = randomNumber(seed + "-length", 1, 3);
|
||||
let suffix = "[" + ((!dynamic) ? length : "") + "]";
|
||||
let type = subType("-index0").type + suffix;
|
||||
return (seed) => {
|
||||
if (dynamic) {
|
||||
length = randomNumber(seed + "-length", 0, 3);
|
||||
}
|
||||
let children = [];
|
||||
for (let i = 0; i < length; i++) {
|
||||
children.push(subType(seed + "-index" + String(i)));
|
||||
}
|
||||
return {
|
||||
type: type,
|
||||
value: children.map((data) => data.value)
|
||||
};
|
||||
};
|
||||
}
|
||||
// Tuple
|
||||
case 9: {
|
||||
let count = randomNumber(seed + "-count", 1, 8);
|
||||
let subTypes = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
let cSeed = seed + "-subtype" + String(i);
|
||||
subTypes.push(generateTest(cSeed));
|
||||
}
|
||||
let type = "tuple(" + subTypes.map(s => s("-index0").type).join(",") + ")";
|
||||
let struct = "Struct" + randomHexString(seed + "-name", 4).substring(2);
|
||||
return (seed) => {
|
||||
let children = [];
|
||||
subTypes.forEach((subType) => {
|
||||
children.push(subType(seed + "-value"));
|
||||
});
|
||||
return {
|
||||
type: type,
|
||||
struct: struct,
|
||||
value: children.map(c => c.value),
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
throw new Error("bad things");
|
||||
return null;
|
||||
}
|
||||
// Returns true iff the types are able to be non-standard pack encoded
|
||||
function checkPack(types) {
|
||||
for (let i = 0; i < types.length; i++) {
|
||||
let type = types[i];
|
||||
if (hasPrefix(type, "tuple")) {
|
||||
return false;
|
||||
}
|
||||
if (hasPrefix(type, "bytes[")) {
|
||||
return false;
|
||||
}
|
||||
if (hasPrefix(type, "string[")) {
|
||||
return false;
|
||||
}
|
||||
let firstDynamic = type.indexOf("[]");
|
||||
if (firstDynamic >= 0 && firstDynamic != type.length - 2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Generates a Solidity source files with the parameter types and values
|
||||
function generateSolidity(params) {
|
||||
let plist = [];
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
plist.push("p" + String(i));
|
||||
}
|
||||
let genCodes = params.map(p => getGenCode(p));
|
||||
let code = new Code();
|
||||
///////////////////
|
||||
// Pragma
|
||||
code.add("pragma experimental ABIEncoderV2;");
|
||||
code.add("pragma solidity ^0.5.5;");
|
||||
code.add("");
|
||||
///////////////////
|
||||
// Header
|
||||
code.add("contract Test {");
|
||||
///////////////////
|
||||
// Structs
|
||||
genCodes.forEach((genCode) => {
|
||||
genCode.structs(code);
|
||||
});
|
||||
///////////////////
|
||||
// test function
|
||||
code.add("function test() public pure returns (" + genCodes.map((g, i) => (g.decl("p" + String(i)))).join(", ") + ") {");
|
||||
genCodes.forEach((genCode, index) => {
|
||||
genCode.assign("p" + index, code);
|
||||
});
|
||||
code.add("}");
|
||||
///////////////////
|
||||
// encode
|
||||
code.add("function encode() public pure returns (bytes memory data){");
|
||||
code.comment("Declare all parameters");
|
||||
genCodes.forEach((genCode, index) => {
|
||||
code.add(genCode.decl("p" + index) + ";");
|
||||
});
|
||||
code.comment("Assign all parameters");
|
||||
genCodes.forEach((genCode, index) => {
|
||||
genCode.assign("p" + index, code);
|
||||
});
|
||||
code.add("");
|
||||
code.add("return abi.encode(" + params.map((p, i) => ("p" + i)).join(", ") + ");");
|
||||
code.add("}");
|
||||
///////////////////
|
||||
// encodePacked
|
||||
if (checkPack(params.map(p => p.type))) {
|
||||
code.add("function encodePacked() public pure returns (bytes memory data){");
|
||||
code.comment("Declare all parameters");
|
||||
genCodes.forEach((genCode, index) => {
|
||||
code.add(genCode.decl("p" + index) + ";");
|
||||
});
|
||||
code.comment("Assign all parameters");
|
||||
genCodes.forEach((genCode, index) => {
|
||||
genCode.assign("p" + index, code);
|
||||
});
|
||||
code.add("");
|
||||
code.add("return abi.encodePacked(" + params.map((p, i) => ("p" + i)).join(", ") + ");");
|
||||
code.add("}");
|
||||
}
|
||||
///////////////////
|
||||
// Footer
|
||||
code.add("}");
|
||||
return code.code;
|
||||
}
|
||||
for (let i = 0; i < 100; i++) {
|
||||
let params = [];
|
||||
console.log(i, randomNumber(String(i) + "-length", 1, 6));
|
||||
let length = randomNumber(String(i) + "-length", 1, 6);
|
||||
for (let j = 0; j < length; j++) {
|
||||
params.push(generateTest(String(i) + String(j) + "-type")(String(i) + String(j) + "-test"));
|
||||
}
|
||||
let solidity = generateSolidity(params);
|
||||
console.log(solidity);
|
||||
console.log(i);
|
||||
let bytecode = solc.compile(solidity)[0].bytecode;
|
||||
//console.log(params.map(p => p.type).join(", "));
|
||||
//console.log(bytecode);
|
||||
let testcase = {
|
||||
//solidity: solidity,
|
||||
bytecode: bytecode,
|
||||
types: params.map(p => p.type),
|
||||
value: params.map(p => p.value),
|
||||
};
|
||||
console.log(testcase);
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
'use strict';
|
||||
import fs from "fs";
|
||||
import { resolve } from "path";
|
||||
import * as bip39 from "bip39";
|
||||
import { HDNode } from "bitcoinjs-lib";
|
||||
import * as ethereumUtil from "ethereumjs-util";
|
||||
import { randomHexString, randomNumber, saveTests } from "..";
|
||||
function getPath(seed) {
|
||||
let path = "m";
|
||||
let count = randomNumber(seed + "-getPath-1", 1, 7);
|
||||
let hardened = randomNumber(seed + "-getPath-2", 0, count + 2);
|
||||
for (let i = 0; i < count; i++) {
|
||||
path += "/" + randomNumber(seed + "-getPath-3" + i, 0, 12);
|
||||
if (i < hardened) {
|
||||
path += "'";
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
function getHD(seed) {
|
||||
let rootNode = HDNode.fromSeedHex(seed);
|
||||
let privateKey = rootNode.keyPair.d.toBuffer(32);
|
||||
let hdnodes = [{
|
||||
path: 'm',
|
||||
privateKey: '0x' + privateKey.toString('hex'),
|
||||
address: '0x' + ethereumUtil.privateToAddress(privateKey).toString('hex'),
|
||||
}];
|
||||
for (let j = 0; j < 5; j++) {
|
||||
let path = getPath(seed + '-hdnode-' + j);
|
||||
let node = rootNode.derivePath(path);
|
||||
let privateKey = node.keyPair.d.toBuffer(32);
|
||||
hdnodes.push({
|
||||
path: path,
|
||||
privateKey: '0x' + privateKey.toString('hex'),
|
||||
address: '0x' + ethereumUtil.privateToAddress(privateKey).toString('hex'),
|
||||
});
|
||||
}
|
||||
return hdnodes;
|
||||
}
|
||||
const testcases = [];
|
||||
// https://medium.com/@alexberegszaszi/why-do-my-bip32-wallets-disagree-6f3254cc5846#.6tqszlvf4
|
||||
testcases.push({
|
||||
name: "axic",
|
||||
locale: "en",
|
||||
entropy: '0xb0a30c7e93a58094d213c4c0aaba22da',
|
||||
mnemonic: 'radar blur cabbage chef fix engine embark joy scheme fiction master release',
|
||||
seed: '0xed37b3442b3d550d0fbb6f01f20aac041c245d4911e13452cac7b1676a070eda66771b71c0083b34cc57ca9c327c459a0ec3600dbaf7f238ff27626c8430a806',
|
||||
hdnodes: [
|
||||
{
|
||||
path: "m/44'/60'/0'/0/0",
|
||||
address: '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9',
|
||||
privateKey: '0xb96e9ccb774cc33213cbcb2c69d3cdae17b0fe4888a1ccd343cbd1a17fd98b18',
|
||||
}
|
||||
]
|
||||
});
|
||||
["en", "es", "fr", "it", "ja", "ko", "zh_cn", "zh_tw"].forEach((locale) => {
|
||||
let tests = JSON.parse(fs.readFileSync(resolve(__dirname, "../input/easyseed-bip39/bip39_vectors." + locale + ".json")).toString());
|
||||
tests.forEach((test, index) => {
|
||||
testcases.push({
|
||||
name: ("easyseed-" + locale + "-" + index),
|
||||
entropy: "0x" + test.entropy,
|
||||
locale: locale,
|
||||
mnemonic: test.mnemonic,
|
||||
password: (test.passphrase || ''),
|
||||
seed: "0x" + test.seed,
|
||||
hdnodes: []
|
||||
});
|
||||
});
|
||||
});
|
||||
console.log("@TODO: This should be 1024");
|
||||
for (let i = 0; i < 10; i++) {
|
||||
let strength = 16 + 4 * randomNumber('random-1-' + i, 0, 5);
|
||||
let entropy = randomHexString('random-2-' + i, strength);
|
||||
let mnemonic = bip39.entropyToMnemonic(entropy.substring(2));
|
||||
let seed = bip39.mnemonicToSeedHex(mnemonic);
|
||||
testcases.push({
|
||||
name: "random-" + i,
|
||||
locale: "en",
|
||||
entropy: entropy,
|
||||
mnemonic: mnemonic,
|
||||
seed: '0x' + seed,
|
||||
hdnodes: getHD(seed),
|
||||
});
|
||||
}
|
||||
let trezor = require('../input/tests-trezor-bip39.json');
|
||||
trezor.english.forEach((testcase, i) => {
|
||||
testcases.push({
|
||||
name: "trezor-" + i,
|
||||
locale: "en",
|
||||
entropy: '0x' + testcase[0],
|
||||
mnemonic: testcase[1],
|
||||
seed: '0x' + testcase[2],
|
||||
hdnodes: getHD(testcase[2]),
|
||||
password: 'TREZOR',
|
||||
});
|
||||
});
|
||||
/*
|
||||
let seed = bip39.mnemonicToSeedHex('radar blur cabbage chef fix engine embark joy scheme fiction master release');
|
||||
console.log('Seed', seed);
|
||||
let entropy = bip39.mnemonicToEntropy('radar blur cabbage chef fix engine embark joy scheme fiction master release');
|
||||
console.log('Entropy', entropy);
|
||||
let rootNode = HDNode.fromSeedHex(seed);
|
||||
let node = rootNode.derivePath("m/44'/60'/0'/0/0");
|
||||
console.log('PrivateKey', node.keyPair.d.toBuffer(32).toString('hex')),
|
||||
*/
|
||||
saveTests('hdnode', testcases);
|
@ -1,6 +0,0 @@
|
||||
'use strict';
|
||||
import fs from "fs";
|
||||
import { resolve } from "path";
|
||||
import { saveTests } from "..";
|
||||
const testcases = JSON.parse(fs.readFileSync(resolve(__dirname, "../input/nameprep-josefsson-idn.json")).toString());
|
||||
saveTests("nameprep", testcases);
|
@ -1,6 +0,0 @@
|
||||
'use strict';
|
||||
import fs from "fs";
|
||||
import { resolve } from "path";
|
||||
import { saveTests } from "..";
|
||||
const testcases = JSON.parse(fs.readFileSync(resolve(__dirname, "../input/units.json")).toString());
|
||||
saveTests("units", testcases);
|
@ -1,26 +0,0 @@
|
||||
'use strict';
|
||||
import fs from "fs";
|
||||
import { resolve } from "path";
|
||||
import { saveTests } from "..";
|
||||
const testcases = [];
|
||||
const mnemonics = {
|
||||
'15db397ed5f682acb22b0afc6c8de4cdfbda7cbc': 'debris glass rich exotic window other film slow expose flight either wealth',
|
||||
'012363d61bdc53d0290a0f25e9c89f8257550fb8': 'service basket parent alcohol fault similar survey twelve hockey cloud walk panel'
|
||||
};
|
||||
const inputDir = resolve(__dirname, "../input/wallets");
|
||||
fs.readdirSync(inputDir).forEach((filename) => {
|
||||
let content = fs.readFileSync(resolve(inputDir, filename)).toString();
|
||||
let data = JSON.parse(content);
|
||||
const comps = filename.split(".")[0].split("-");
|
||||
testcases.push({
|
||||
name: comps[1],
|
||||
type: (data.ethaddr ? "crowdsale" : "secret-storage"),
|
||||
hasAddress: !!data.address,
|
||||
address: ("0x" + comps[2]),
|
||||
privateKey: ("0x" + comps[3]),
|
||||
mnemonic: (mnemonics[comps[2]] || null),
|
||||
password: comps[4],
|
||||
json: content
|
||||
});
|
||||
});
|
||||
saveTests("wallets", testcases);
|
@ -1,13 +0,0 @@
|
||||
'use strict';
|
||||
import fs from "fs";
|
||||
import { resolve } from "path";
|
||||
import { saveTests } from "..";
|
||||
const testcases = [];
|
||||
["cz", "en", "es", "fr", "it", "ja", "ko", "zh_cn", "zh_tw"].forEach((locale) => {
|
||||
let content = fs.readFileSync(resolve(__dirname, "../../input/wordlists", "lang-" + locale + ".txt")).toString();
|
||||
testcases.push({
|
||||
content: content,
|
||||
locale: locale
|
||||
});
|
||||
});
|
||||
saveTests("wordlists", testcases);
|
Loading…
Reference in New Issue
Block a user