update client to use eip712 signature instead of snapshot_id

This commit is contained in:
boneyard93501
2021-11-06 18:51:59 -05:00
parent dea3be5d4e
commit 8b902b259e
16 changed files with 23 additions and 915 deletions

View File

@ -80,10 +80,10 @@ export function registerEIPValidator(...args: any) {
export interface DataProviderDef {
delete_records: (password: string, callParams: CallParams<'password'>) => { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; } | Promise<{ stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; }>;
get_record: (snapshot_id: number, callParams: CallParams<'snapshot_id'>) => { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; } | Promise<{ stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; }>;
delete_records: (password: string, callParams: CallParams<'password'>) => { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: string; signed_response: string; timestamp: number; ts_validation: boolean; }[]; } | Promise<{ stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: string; signed_response: string; timestamp: number; ts_validation: boolean; }[]; }>;
get_record: (signature: string, callParams: CallParams<'signature'>) => { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: string; signed_response: string; timestamp: number; ts_validation: boolean; }[]; } | Promise<{ stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: string; signed_response: string; timestamp: number; ts_validation: boolean; }[]; }>;
get_record_count: (callParams: CallParams<null>) => number | Promise<number>;
get_records: (callParams: CallParams<null>) => { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; } | Promise<{ stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; }>;
get_records: (callParams: CallParams<null>) => { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: string; signed_response: string; timestamp: number; ts_validation: boolean; }[]; } | Promise<{ stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: string; signed_response: string; timestamp: number; ts_validation: boolean; }[]; }>;
}
export function registerDataProvider(service: DataProviderDef): void;
export function registerDataProvider(serviceId: string, service: DataProviderDef): void;
@ -115,7 +115,7 @@ export function registerDataProvider(...args: any) {
"functionName" : "get_record",
"argDefs" : [
{
"name" : "snapshot_id",
"name" : "signature",
"argType" : {
"tag" : "primitive"
}
@ -148,9 +148,9 @@ export function registerDataProvider(...args: any) {
// Functions
export type Get_recordResult = { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; }
export function get_record(snapshot_id: number, node: string, relay: string, config?: {ttl?: number}): Promise<Get_recordResult>;
export function get_record(peer: FluencePeer, snapshot_id: number, node: string, relay: string, config?: {ttl?: number}): Promise<Get_recordResult>;
export type Get_recordResult = { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: string; signed_response: string; timestamp: number; ts_validation: boolean; }[]; }
export function get_record(signature: string, node: string, relay: string, config?: {ttl?: number}): Promise<Get_recordResult>;
export function get_record(peer: FluencePeer, signature: string, node: string, relay: string, config?: {ttl?: number}): Promise<Get_recordResult>;
export function get_record(...args: any) {
let script = `
@ -165,7 +165,7 @@ export function get_record(...args: any) {
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "snapshot_id") [] snapshot_id)
(call %init_peer_id% ("getDataSrv" "signature") [] signature)
)
(call %init_peer_id% ("getDataSrv" "node") [] node)
)
@ -176,7 +176,7 @@ export function get_record(...args: any) {
(call relay ("op" "noop") [])
)
(xor
(call node ("DataProvider" "get_record") [snapshot_id] res)
(call node ("DataProvider" "get_record") [signature] res)
(seq
(seq
(seq
@ -210,7 +210,7 @@ export function get_record(...args: any) {
},
"argDefs" : [
{
"name" : "snapshot_id",
"name" : "signature",
"argType" : {
"tag" : "primitive"
}
@ -243,7 +243,7 @@ export function get_record(...args: any) {
}
export type Delete_recordsResult = { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; }
export type Delete_recordsResult = { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: string; signed_response: string; timestamp: number; ts_validation: boolean; }[]; }
export function delete_records(password: string, node: string, relay: string, config?: {ttl?: number}): Promise<Delete_recordsResult>;
export function delete_records(peer: FluencePeer, password: string, node: string, relay: string, config?: {ttl?: number}): Promise<Delete_recordsResult>;
export function delete_records(...args: any) {
@ -519,7 +519,7 @@ export function get_record_count(...args: any) {
}
export type Get_recordsResult = { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; event_signature: string; peer_id: string; signed_response: string; snapshot_id: number; timestamp: number; ts_validation: boolean; }[]; }
export type Get_recordsResult = { stderr: string; stdout: { eip712_doc: string; eip_validation: boolean; event_address: string; peer_id: string; signature: string; signed_response: string; timestamp: number; ts_validation: boolean; }[]; }
export function get_records(node: string, relay: string, config?: {ttl?: number}): Promise<Get_recordsResult>;
export function get_records(peer: FluencePeer, node: string, relay: string, config?: {ttl?: number}): Promise<Get_recordsResult>;
export function get_records(...args: any) {

View File

@ -58,7 +58,7 @@ async function main() {
let _res = await delete_records(NODE_DB_PWD, poc_topologies[0].node_id, poc_topologies[0].relay_id);
}
console.log("Lets validate proposal %s, which is old and should fail.", EIP712_URL);
console.log("Let's validate proposal %s, which is old and should fail.", EIP712_URL);
let doc_val = await validate(EIP712_URL, poc_topologies[0].node_id, poc_topologies[0].relay_id);
// if (doc_val.stderr.length > 0) {}
console.log("signed eip validation result: ", doc_val);
@ -71,12 +71,12 @@ async function main() {
console.log("We should have one record in the node db and have %s record(s).", records.stdout.length);
}
console.log("We know from the EIP document that the snapshot is 9278489, which i sued as a unique key in the sqlite db.")
console.log(" and we can call individual recirds by snapshot:")
let good_record = await get_record(9278489, poc_topologies[0].node_id, poc_topologies[0].relay_id);
let bad_record = await get_record(92784890, poc_topologies[0].node_id, poc_topologies[0].relay_id);
console.log("result for call with 9278489: ", good_record);
console.log("result for call with bad 92784890: ", bad_record);
console.log("We know from the EIP document that the signature is 0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1c, which is used as a unique key in the sqlite db.")
console.log(" and we can call individual records by signature.")
let good_record = await get_record("0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1c", poc_topologies[0].node_id, poc_topologies[0].relay_id);
let bad_record = await get_record("0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1cX", poc_topologies[0].node_id, poc_topologies[0].relay_id);
console.log("result for call with 0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1c: ", good_record);
console.log("result for call with bad 0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1cX: ", bad_record);
return;
}