no-yolo-signatures
Advanced tools
Comparing version
@@ -10,3 +10,3 @@ import { Address, Transaction, TokenList, GenericAddressList } from "./types"; | ||
} | ||
interface TokenAddressInfo { | ||
export interface TokenAddressInfo { | ||
type: AddressInfoType.TokenListInfo; | ||
@@ -18,4 +18,5 @@ chainId: number; | ||
logoURI: string; | ||
source: string; | ||
} | ||
interface GenericAddressInfo { | ||
export interface GenericAddressInfo { | ||
type: AddressInfoType.GenericAddressInfo; | ||
@@ -27,2 +28,3 @@ chainId: number; | ||
logoURI: string; | ||
source: string; | ||
} | ||
@@ -43,5 +45,14 @@ interface ContextAddressInfo { | ||
} | ||
export declare enum BuiltInAddressInfoFetchersType { | ||
TokenList = "TokenList", | ||
GenericAddressList = "GenericAddressList", | ||
Context = "Context" | ||
} | ||
export declare type BuiltInAddressInfoFetcher = TokenListAddressInfoFetcher | GenericAddressListInfoFetcher | ContextAddressInfoFetcher; | ||
export declare class TokenListAddressInfoFetcher implements AddressInfoFetcher { | ||
readonly tokenList: TokenList; | ||
constructor(tokenList: TokenList); | ||
readonly source: string; | ||
readonly type = BuiltInAddressInfoFetchersType.TokenList; | ||
static fromURL(url: string): Promise<TokenListAddressInfoFetcher>; | ||
constructor(tokenList: TokenList, source: string); | ||
fetchInfo(address: Address): Promise<Array<AddressInfo>>; | ||
@@ -51,9 +62,13 @@ } | ||
readonly addressList: GenericAddressList; | ||
constructor(addressList: GenericAddressList); | ||
readonly source: string; | ||
readonly type = BuiltInAddressInfoFetchersType.GenericAddressList; | ||
static fromURL(url: string): Promise<GenericAddressListInfoFetcher>; | ||
constructor(addressList: GenericAddressList, source: string); | ||
fetchInfo(address: Address): Promise<Array<AddressInfo>>; | ||
} | ||
export declare class ContextAddressInfoFetcher implements AddressInfoFetcher { | ||
readonly type = BuiltInAddressInfoFetchersType.Context; | ||
fetchInfo(address: Address, context: AddressInfoFetchContext): Promise<ContextAddressInfo[]>; | ||
} | ||
export declare const getAddressInfoFetchersForChainId: (chainId: number) => (TokenListAddressInfoFetcher | GenericAddressListInfoFetcher | ContextAddressInfoFetcher)[]; | ||
export declare const getAddressInfoFetchersForChainId: (chainId: number) => Promise<(TokenListAddressInfoFetcher | GenericAddressListInfoFetcher | ContextAddressInfoFetcher)[]>; | ||
export {}; |
@@ -13,5 +13,45 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getAddressInfoFetchersForChainId = exports.ContextAddressInfoFetcher = exports.GenericAddressListInfoFetcher = exports.TokenListAddressInfoFetcher = exports.ContextInfoType = exports.AddressInfoType = void 0; | ||
exports.getAddressInfoFetchersForChainId = exports.ContextAddressInfoFetcher = exports.GenericAddressListInfoFetcher = exports.TokenListAddressInfoFetcher = exports.BuiltInAddressInfoFetchersType = exports.ContextInfoType = exports.AddressInfoType = void 0; | ||
var _1 = require("."); | ||
var cross_fetch_1 = __importDefault(require("cross-fetch")); | ||
var AddressInfoType; | ||
@@ -27,6 +67,30 @@ (function (AddressInfoType) { | ||
})(ContextInfoType = exports.ContextInfoType || (exports.ContextInfoType = {})); | ||
var BuiltInAddressInfoFetchersType; | ||
(function (BuiltInAddressInfoFetchersType) { | ||
BuiltInAddressInfoFetchersType["TokenList"] = "TokenList"; | ||
BuiltInAddressInfoFetchersType["GenericAddressList"] = "GenericAddressList"; | ||
BuiltInAddressInfoFetchersType["Context"] = "Context"; | ||
})(BuiltInAddressInfoFetchersType = exports.BuiltInAddressInfoFetchersType || (exports.BuiltInAddressInfoFetchersType = {})); | ||
var TokenListAddressInfoFetcher = /** @class */ (function () { | ||
function TokenListAddressInfoFetcher(tokenList) { | ||
function TokenListAddressInfoFetcher(tokenList, source) { | ||
this.tokenList = tokenList; | ||
this.source = source; | ||
this.type = BuiltInAddressInfoFetchersType.TokenList; | ||
} | ||
TokenListAddressInfoFetcher.fromURL = function (url) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var resp, json; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, (0, cross_fetch_1.default)(url)]; | ||
case 1: | ||
resp = _a.sent(); | ||
return [4 /*yield*/, resp.json()]; | ||
case 2: | ||
json = _a.sent(); | ||
return [2 /*return*/, new this(json, url)]; | ||
} | ||
}); | ||
}); | ||
}; | ||
TokenListAddressInfoFetcher.prototype.fetchInfo = function (address) { | ||
@@ -37,3 +101,3 @@ var match = this.tokenList.tokens.find(function (_) { return _.address === address; }); | ||
} | ||
return Promise.resolve([__assign({ type: AddressInfoType.TokenListInfo }, match)]); | ||
return Promise.resolve([__assign(__assign({ type: AddressInfoType.TokenListInfo }, match), { source: this.source })]); | ||
}; | ||
@@ -44,5 +108,23 @@ return TokenListAddressInfoFetcher; | ||
var GenericAddressListInfoFetcher = /** @class */ (function () { | ||
function GenericAddressListInfoFetcher(addressList) { | ||
function GenericAddressListInfoFetcher(addressList, source) { | ||
this.addressList = addressList; | ||
this.source = source; | ||
this.type = BuiltInAddressInfoFetchersType.GenericAddressList; | ||
} | ||
GenericAddressListInfoFetcher.fromURL = function (url) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var resp, json; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, (0, cross_fetch_1.default)(url)]; | ||
case 1: | ||
resp = _a.sent(); | ||
return [4 /*yield*/, resp.json()]; | ||
case 2: | ||
json = _a.sent(); | ||
return [2 /*return*/, new this(json, url)]; | ||
} | ||
}); | ||
}); | ||
}; | ||
GenericAddressListInfoFetcher.prototype.fetchInfo = function (address) { | ||
@@ -53,3 +135,3 @@ var match = this.addressList.addresses.find(function (_) { return _.address === address; }); | ||
} | ||
return Promise.resolve([__assign({ type: AddressInfoType.GenericAddressInfo }, match)]); | ||
return Promise.resolve([__assign(__assign({ type: AddressInfoType.GenericAddressInfo }, match), { source: this.source })]); | ||
}; | ||
@@ -61,2 +143,3 @@ return GenericAddressListInfoFetcher; | ||
function ContextAddressInfoFetcher() { | ||
this.type = BuiltInAddressInfoFetchersType.Context; | ||
} | ||
@@ -75,15 +158,40 @@ ContextAddressInfoFetcher.prototype.fetchInfo = function (address, context) { | ||
exports.ContextAddressInfoFetcher = ContextAddressInfoFetcher; | ||
var getAddressInfoFetchersForChainId = function (chainId) { | ||
var contextFetcher = new ContextAddressInfoFetcher(); | ||
var network = _1.NETWORKS[chainId]; | ||
if (!network) { | ||
return [contextFetcher]; | ||
} | ||
return [ | ||
network.genericAddressList ? [new GenericAddressListInfoFetcher(network.genericAddressList)] : [], | ||
network.tokenList ? [new TokenListAddressInfoFetcher(network.tokenList)] : [], | ||
[contextFetcher] | ||
].flat(); | ||
}; | ||
var getAddressInfoFetchersForChainId = function (chainId) { return __awaiter(void 0, void 0, void 0, function () { | ||
var contextFetcher, network, _a, _b, _c; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: | ||
contextFetcher = new ContextAddressInfoFetcher(); | ||
network = _1.NETWORKS[chainId]; | ||
if (!network) { | ||
return [2 /*return*/, [contextFetcher]]; | ||
} | ||
if (!network.genericAddressListUrl) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, GenericAddressListInfoFetcher.fromURL(network.genericAddressListUrl)]; | ||
case 1: | ||
_a = [_d.sent()]; | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
_a = []; | ||
_d.label = 3; | ||
case 3: | ||
_b = [ | ||
_a | ||
]; | ||
if (!network.tokenListUrl) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, TokenListAddressInfoFetcher.fromURL(network.tokenListUrl)]; | ||
case 4: | ||
_c = [_d.sent()]; | ||
return [3 /*break*/, 6]; | ||
case 5: | ||
_c = []; | ||
_d.label = 6; | ||
case 6: return [2 /*return*/, _b.concat([ | ||
_c, | ||
[contextFetcher] | ||
]).flat()]; | ||
} | ||
}); | ||
}); }; | ||
exports.getAddressInfoFetchersForChainId = getAddressInfoFetchersForChainId; | ||
//# sourceMappingURL=addressInfo.js.map |
@@ -49,6 +49,8 @@ "use strict"; | ||
celoAbiFetchers = (0, _1.getAbiFetchersForChainId)(42220); | ||
celoAddressInfoFetchers = (0, _1.getAddressInfoFetchersForChainId)(42220); | ||
return [4 /*yield*/, (0, _1.getAddressInfoFetchersForChainId)(42220)]; | ||
case 1: | ||
celoAddressInfoFetchers = _a.sent(); | ||
parser = new parser_1.Parser({ abiFetchers: celoAbiFetchers, addressInfoFetchers: celoAddressInfoFetchers }); | ||
provider = new ethers_1.ethers.providers.JsonRpcProvider('https://forno.celo.org'); | ||
if (!(process.argv.length > 3)) return [3 /*break*/, 2]; | ||
if (!(process.argv.length > 3)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, parser.parseAsResult({ | ||
@@ -60,3 +62,3 @@ from: '', | ||
})]; | ||
case 1: | ||
case 2: | ||
parseResult = _a.sent(); | ||
@@ -69,7 +71,7 @@ if (!parseResult.transactionDescription.ok) { | ||
console.log(parser.formatTxDescriptionToHuman(parseResult.transactionDescription.result, parseResult.addressInfo)); | ||
return [3 /*break*/, 5]; | ||
case 2: | ||
return [3 /*break*/, 6]; | ||
case 3: | ||
txHash = process.argv[2]; | ||
return [4 /*yield*/, provider.getTransaction(txHash)]; | ||
case 3: | ||
case 4: | ||
tx = _a.sent(); | ||
@@ -82,3 +84,3 @@ return [4 /*yield*/, parser.parseAsResult({ | ||
})]; | ||
case 4: | ||
case 5: | ||
parseResult = _a.sent(); | ||
@@ -90,4 +92,4 @@ if (!parseResult.transactionDescription.ok) { | ||
console.log(parser.formatTxDescriptionToHuman(parseResult.transactionDescription.result, parseResult.addressInfo)); | ||
_a.label = 5; | ||
case 5: return [2 /*return*/]; | ||
_a.label = 6; | ||
case 6: return [2 /*return*/]; | ||
} | ||
@@ -94,0 +96,0 @@ }); |
@@ -1,2 +0,1 @@ | ||
import { GenericAddressList, TokenList } from "."; | ||
export declare const NETWORKS: { | ||
@@ -8,6 +7,7 @@ [chainId: number]: { | ||
explorerAPIURL: string; | ||
explorerName: string; | ||
rpcURL: string; | ||
genericAddressList?: GenericAddressList; | ||
tokenList?: TokenList; | ||
genericAddressListUrl?: string; | ||
tokenListUrl?: string; | ||
}; | ||
}; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NETWORKS = void 0; | ||
var celoTokenList_json_1 = __importDefault(require("./static/celoTokenList.json")); | ||
var ethTokenList_json_1 = __importDefault(require("./static/ethTokenList.json")); | ||
var celoGenericAddressList_json_1 = __importDefault(require("./static/celoGenericAddressList.json")); | ||
exports.NETWORKS = { | ||
@@ -16,4 +10,5 @@ 1: { | ||
explorerAPIURL: "https://api.etherscan.io", | ||
explorerName: "Etherscan", | ||
rpcURL: "https://mainnet-nethermind.blockscout.com/", | ||
tokenList: ethTokenList_json_1.default | ||
tokenListUrl: "https://gateway.ipfs.io/ipns/tokens.uniswap.org", | ||
}, | ||
@@ -25,5 +20,6 @@ 42220: { | ||
explorerAPIURL: "https://explorer.celo.org", | ||
explorerName: "Celo Explorer", | ||
rpcURL: "https://forno.celo.org", | ||
genericAddressList: celoGenericAddressList_json_1.default, | ||
tokenList: celoTokenList_json_1.default | ||
genericAddressListUrl: "https://raw.githubusercontent.com/celo-org/no-yolo-signatures/main/src/static/celoGenericAddressList.json", | ||
tokenListUrl: "https://raw.githubusercontent.com/celo-org/no-yolo-signatures/main/src/static/celoTokenList.json" | ||
}, | ||
@@ -33,2 +29,3 @@ 137: { | ||
chainId: 137, | ||
explorerName: "Polygonscan", | ||
explorerURL: "https://polygonscan.com", | ||
@@ -35,0 +32,0 @@ explorerAPIURL: "https://api.polygonscan.com", |
@@ -45,4 +45,14 @@ "use strict"; | ||
var ethAbiFetchers = (0, _1.getAbiFetchersForChainId)(1, { accomodateRateLimit: true }); | ||
var celoAddressInfoFetchers = (0, _1.getAddressInfoFetchersForChainId)(42220); | ||
var celoAddressInfoFetchers; | ||
describe('Real transaction tests', function () { | ||
beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, (0, _1.getAddressInfoFetchersForChainId)(42220)]; | ||
case 1: | ||
celoAddressInfoFetchers = _a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
it('can properly decode a basic Celo TX', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -49,0 +59,0 @@ var parser, provider, txHash, tx, result; |
@@ -14,19 +14,21 @@ import { BigNumberish } from 'ethers'; | ||
} | ||
export interface TokenListEntry { | ||
chainId: number; | ||
symbol: string; | ||
address: Address; | ||
name: string; | ||
logoURI: string; | ||
} | ||
export interface TokenList { | ||
tokens: Array<{ | ||
chainId: number; | ||
symbol: string; | ||
address: Address; | ||
name: string; | ||
logoURI: string; | ||
}>; | ||
tokens: TokenListEntry[]; | ||
} | ||
export interface GenericAddressListEntry { | ||
chainId: number; | ||
address: Address; | ||
name: string; | ||
description: string; | ||
logoURI: string; | ||
} | ||
export interface GenericAddressList { | ||
addresses: Array<{ | ||
chainId: number; | ||
address: Address; | ||
name: string; | ||
description: string; | ||
logoURI: string; | ||
}>; | ||
addresses: GenericAddressListEntry[]; | ||
} |
{ | ||
"name": "no-yolo-signatures", | ||
"version": "0.0.1-alpha2", | ||
"version": "0.0.1-alpha3", | ||
"description": "Tooling to discourage yolo tx signing", | ||
@@ -5,0 +5,0 @@ "author": "Nam Chu Hoai", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
133431
6.33%2063
6.95%