mirror of
https://github.com/fluencelabs/eip712-validation-node
synced 2025-05-28 23:41:20 +00:00
update workflow, demo aqua
This commit is contained in:
parent
f11396b916
commit
aa69c42dc0
@ -7,11 +7,11 @@ data PVResponse:
|
||||
data DBResponse:
|
||||
snapshot_id: u64
|
||||
|
||||
service ProVoValidation("eip_validation"):
|
||||
service ProVoValidation("snapshot"):
|
||||
eip712_validation_string(eip_str: string, peer_id: string) -> string
|
||||
eip712_validation_url(eip_str: string, peer_id: string) -> string
|
||||
|
||||
service DataProvider(""):
|
||||
service DataProvider("snapshot"):
|
||||
get_records() -> []DBResponse
|
||||
get_record(snapshot_id: u64) -> DBResponse
|
||||
|
||||
|
@ -85,7 +85,7 @@ export function registerProVoValidation(...args: any) {
|
||||
if (!!incorrectServiceDefinitions.length) {
|
||||
throw new Error(
|
||||
"Error registering service ProVoValidation: missing functions: " +
|
||||
incorrectServiceDefinitions.map((d) => "'" + d + "'").join(", ")
|
||||
incorrectServiceDefinitions.map((d) => "'" + d + "'").join(", ")
|
||||
);
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ export function registerDataProvider(...args: any) {
|
||||
if (!!incorrectServiceDefinitions.length) {
|
||||
throw new Error(
|
||||
"Error registering service DataProvider: missing functions: " +
|
||||
incorrectServiceDefinitions.map((d) => "'" + d + "'").join(", ")
|
||||
incorrectServiceDefinitions.map((d) => "'" + d + "'").join(", ")
|
||||
);
|
||||
}
|
||||
|
||||
|
135
src/index.ts
135
src/index.ts
@ -9,9 +9,13 @@ import got from 'got';
|
||||
import { base64 } from "ethers/lib/utils";
|
||||
|
||||
|
||||
// Arbitrary secret key that could be read from file, CLI arg or db
|
||||
// We derive both the PeerId and the (ethers) wallet from this key
|
||||
const SecretKey = "0x0123456789012345678901234567890123456789012345678901234567890123";
|
||||
|
||||
function create_wallet(): ethers.Wallet {
|
||||
return ethers.Wallet.createRandom();
|
||||
|
||||
function create_wallet(sk: string): ethers.Wallet {
|
||||
return new ethers.Wallet(sk);
|
||||
}
|
||||
|
||||
function sign_response(wallet: ethers.Wallet, response: Response): Promise<string> {
|
||||
@ -22,7 +26,7 @@ class EIPValidator implements ProVoValidationDef {
|
||||
|
||||
async eip712_validation_string(eip712_json: string): Promise<string> {
|
||||
// todo: need to fix this to use local peer key
|
||||
const wallet = create_wallet();
|
||||
const wallet = create_wallet(SecretKey);
|
||||
let response = eip_validation(eip712_json, wallet.address);
|
||||
|
||||
const resp_str = JSON.stringify(response);
|
||||
@ -46,7 +50,7 @@ class EIPValidator implements ProVoValidationDef {
|
||||
const eip_json = eip.body;
|
||||
|
||||
// todo: need to fix this to use local peer key
|
||||
const wallet = create_wallet();
|
||||
const wallet = create_wallet(SecretKey);
|
||||
let response = eip_validation(eip_json, wallet.address);
|
||||
|
||||
const resp_str = JSON.stringify(response);
|
||||
@ -64,7 +68,6 @@ class EIPValidator implements ProVoValidationDef {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DataProvider implements DataProviderDef {
|
||||
|
||||
get_record(snapshot_id: number) {
|
||||
@ -79,123 +82,43 @@ class DataProvider implements DataProviderDef {
|
||||
}
|
||||
|
||||
|
||||
async function main_0() {
|
||||
|
||||
await startFluencePeer();
|
||||
|
||||
// const peer_data = Fluence.getPeer();
|
||||
// console.log("client data\n: ", peer_data);
|
||||
|
||||
console.log("application started");
|
||||
console.log("peer id is: ", Fluence.getStatus().peerId);
|
||||
console.log("relay is: ", Fluence.getStatus().relayPeerId);
|
||||
|
||||
registerProVoValidation(new EIPValidator());
|
||||
registerDataProvider(new DataProvider);
|
||||
|
||||
// test
|
||||
|
||||
|
||||
// await Fluence.stop();
|
||||
|
||||
}
|
||||
|
||||
|
||||
async function startFluencePeer() {
|
||||
const skBase64 = 'z1x3cVXhk9nJKE1pZaX9KxccUBzxu3aGlaUjDdAB2oY=';
|
||||
const skBytes = base64.decode(skBase64);
|
||||
|
||||
async function startFluencePeer(skBytes: Uint8Array): Promise<void> {
|
||||
await Fluence.start({
|
||||
connectTo: krasnodar[0],
|
||||
KeyPair: await KeyPair.fromEd25519SK(skBytes)
|
||||
});
|
||||
}
|
||||
|
||||
async function main_2() {
|
||||
/*
|
||||
const DB_PATH = './data/snapshot.db';
|
||||
|
||||
// https://ipfs.fleek.co/ipfs/QmWGzSQFm57ohEq2ATw4UNHWmYU2HkMjtedcNLodYywpmS
|
||||
// should come from Aqua
|
||||
// note: I changed \" to \\" in order for JSON.parse to work
|
||||
const eip712_doc = `{"address":"0xeF8305E140ac520225DAf050e2f71d5fBcC543e7","sig":"0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1c","data":{"domain":{"name":"snapshot","version":"0.1.4"},"types":{"Proposal":[{"name":"from","type":"address"},{"name":"space","type":"string"},{"name":"timestamp","type":"uint64"},{"name":"type","type":"string"},{"name":"title","type":"string"},{"name":"body","type":"string"},{"name":"choices","type":"string[]"},{"name":"start","type":"uint64"},{"name":"end","type":"uint64"},{"name":"snapshot","type":"uint64"},{"name":"network","type":"string"},{"name":"strategies","type":"string"},{"name":"plugins","type":"string"},{"name":"metadata","type":"string"}]},"message":{"space":"fabien.eth","type":"single-choice","title":"This is a long title this is a long title this is a long title this is a long title this is a long title this is a long","body":"This is a long title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title.","choices":["Approve","Reject"],"start":1630472400,"end":1640926800,"snapshot":9278489,"network":"4","strategies":"[{\\"name\\":\\"ticket\\",\\"params\\":{\\"value\\":100,\\"symbol\\":\\"$\\"}}]","plugins":"{}","metadata":"{}","from":"0xeF8305E140ac520225DAf050e2f71d5fBcC543e7","timestamp":1631432106}}}`;
|
||||
|
||||
// todo: replace with actual peer pk and sk
|
||||
const wallet = create_wallet();
|
||||
const peer_id = wallet.address;
|
||||
let response = await eip_validation(eip712_doc, peer_id);
|
||||
|
||||
|
||||
|
||||
// stringify, hexlify, hash and sign response
|
||||
const resp_str = JSON.stringify(response);
|
||||
console.log("eip validation response: ", resp_str);
|
||||
|
||||
// just sign the raw message string for a long message
|
||||
const signed_response = await wallet.signMessage(resp_str);
|
||||
console.log("signed response: ", signed_response);
|
||||
|
||||
// verify
|
||||
const address = ethers.utils.verifyMessage(resp_str, signed_response);
|
||||
console.log("verify signature. peer_id: ", peer_id, " verified addr: ", address, " equal: ", peer_id === address);
|
||||
|
||||
var db = get_db(DB_PATH);
|
||||
const _table = await create_table(db);
|
||||
console.log("table: ", _table);
|
||||
|
||||
var _insert = await insert_event(db, JSON.parse(eip712_doc), response, signed_response);
|
||||
console.log("insert: ", _insert);
|
||||
|
||||
|
||||
var _select = await select_events();
|
||||
console.log("select all:\n", _select, "\n");
|
||||
|
||||
var _select = await select_event(9278489);
|
||||
console.log("select one (9278489):\n", _select, "\n");
|
||||
|
||||
|
||||
// db.close();
|
||||
*/
|
||||
|
||||
const eip_doc: any = await got('https://ipfs.fleek.co/ipfs/QmWGzSQFm57ohEq2ATw4UNHWmYU2HkMjtedcNLodYywpmS').json();
|
||||
|
||||
console.log("data: ", typeof (eip_doc));
|
||||
// console.log("data: ", eip_doc);
|
||||
console.log("address: ", eip_doc.address);
|
||||
console.log("signature: ", eip_doc.sig);
|
||||
console.log("eip doc ", eip_doc.data);
|
||||
|
||||
|
||||
var response = await eip_validation(JSON.stringify(eip_doc), "1234");
|
||||
console.log(response);
|
||||
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await startFluencePeer()
|
||||
|
||||
console.dir(Fluence);
|
||||
console.log("peer id : ", Fluence.getStatus().peerId);
|
||||
console.log("relay id: ", Fluence.getStatus().relayPeerId);
|
||||
console.log("status : ", Fluence.getStatus());
|
||||
console.log("\n\n");
|
||||
let wallet = new ethers.Wallet(SecretKey);
|
||||
console.log("wallet from sk: ", wallet.address);
|
||||
console.log("wallet pk: ", wallet.publicKey);
|
||||
|
||||
let peer = Fluence.getPeer();
|
||||
const skBytes: Uint8Array = ethers.utils.arrayify(SecretKey);
|
||||
console.log("arraify: ", skBytes);
|
||||
|
||||
await startFluencePeer(skBytes);
|
||||
|
||||
|
||||
console.log("PeerId: ", Fluence.getStatus().peerId);
|
||||
console.log("Relay id: ", Fluence.getStatus().relayPeerId);
|
||||
|
||||
// let peer = Fluence.getPeer();
|
||||
// console.log(peer);
|
||||
// console.log(Fluence.KeyPair);
|
||||
|
||||
|
||||
|
||||
registerProVoValidation(new EIPValidator());
|
||||
registerDataProvider(new DataProvider);
|
||||
|
||||
const eip_doc: any = await got('https://ipfs.fleek.co/ipfs/QmWGzSQFm57ohEq2ATw4UNHWmYU2HkMjtedcNLodYywpmS').json();
|
||||
console.log("eip json obj: ", eip_doc);
|
||||
// const eip_doc: any = await got('https://ipfs.fleek.co/ipfs/QmWGzSQFm57ohEq2ATw4UNHWmYU2HkMjtedcNLodYywpmS').json();
|
||||
// console.log("eip json obj: ", eip_doc);
|
||||
|
||||
let obj = new EIPValidator();
|
||||
let result = obj.eip712_validation_url(JSON.stringify(eip_doc));
|
||||
console.log("result: ", result);
|
||||
await Fluence.stop();
|
||||
// let obj = new EIPValidator();
|
||||
// let result = obj.eip712_validation_url(JSON.stringify(eip_doc));
|
||||
// console.log("result: ", result);
|
||||
|
||||
// await Fluence.stop();
|
||||
}
|
||||
|
||||
main();
|
Loading…
x
Reference in New Issue
Block a user