mirror of
https://github.com/3lLobo/zkAuth.git
synced 2026-01-09 12:27:55 -05:00
prettier 💫
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -15,8 +15,20 @@ directive @derivedFrom(field: String!) on FIELD_DEFINITION
|
||||
type Address {
|
||||
id: ID!
|
||||
address: Bytes!
|
||||
authOutgoing(skip: Int = 0, first: Int = 100, orderBy: Authentication_orderBy, orderDirection: OrderDirection, where: Authentication_filter): [Authentication!]
|
||||
authIncoming(skip: Int = 0, first: Int = 100, orderBy: Authentication_orderBy, orderDirection: OrderDirection, where: Authentication_filter): [Authentication!]
|
||||
authOutgoing(
|
||||
skip: Int = 0
|
||||
first: Int = 100
|
||||
orderBy: Authentication_orderBy
|
||||
orderDirection: OrderDirection
|
||||
where: Authentication_filter
|
||||
): [Authentication!]
|
||||
authIncoming(
|
||||
skip: Int = 0
|
||||
first: Int = 100
|
||||
orderBy: Authentication_orderBy
|
||||
orderDirection: OrderDirection
|
||||
where: Authentication_filter
|
||||
): [Authentication!]
|
||||
}
|
||||
|
||||
input Address_filter {
|
||||
@@ -36,7 +48,9 @@ input Address_filter {
|
||||
address_not_contains: Bytes
|
||||
authOutgoing_: Authentication_filter
|
||||
authIncoming_: Authentication_filter
|
||||
"""Filter for the block changed event."""
|
||||
"""
|
||||
Filter for the block changed event.
|
||||
"""
|
||||
_change_block: BlockChangedFilter
|
||||
}
|
||||
|
||||
@@ -128,7 +142,9 @@ input AuthData_filter {
|
||||
created_ends_with_nocase: String
|
||||
created_not_ends_with: String
|
||||
created_not_ends_with_nocase: String
|
||||
"""Filter for the block changed event."""
|
||||
"""
|
||||
Filter for the block changed event.
|
||||
"""
|
||||
_change_block: BlockChangedFilter
|
||||
}
|
||||
|
||||
@@ -207,7 +223,9 @@ input AuthStatus_filter {
|
||||
validationTime_ends_with_nocase: String
|
||||
validationTime_not_ends_with: String
|
||||
validationTime_not_ends_with_nocase: String
|
||||
"""Filter for the block changed event."""
|
||||
"""
|
||||
Filter for the block changed event.
|
||||
"""
|
||||
_change_block: BlockChangedFilter
|
||||
}
|
||||
|
||||
@@ -310,7 +328,9 @@ input Authentication_filter {
|
||||
created_ends_with_nocase: String
|
||||
created_not_ends_with: String
|
||||
created_not_ends_with_nocase: String
|
||||
"""Filter for the block changed event."""
|
||||
"""
|
||||
Filter for the block changed event.
|
||||
"""
|
||||
_change_block: BlockChangedFilter
|
||||
}
|
||||
|
||||
@@ -340,7 +360,9 @@ input Block_height {
|
||||
|
||||
scalar Bytes
|
||||
|
||||
"""Defines the order direction, either ascending or descending"""
|
||||
"""
|
||||
Defines the order direction, either ascending or descending
|
||||
"""
|
||||
enum OrderDirection {
|
||||
asc
|
||||
desc
|
||||
@@ -451,7 +473,9 @@ type Query {
|
||||
"""
|
||||
subgraphError: _SubgraphErrorPolicy_! = deny
|
||||
): [Address!]!
|
||||
"""Access to subgraph metadata"""
|
||||
"""
|
||||
Access to subgraph metadata
|
||||
"""
|
||||
_meta(block: Block_height): _Meta_
|
||||
}
|
||||
|
||||
@@ -560,40 +584,55 @@ type Subscription {
|
||||
"""
|
||||
subgraphError: _SubgraphErrorPolicy_! = deny
|
||||
): [Address!]!
|
||||
"""Access to subgraph metadata"""
|
||||
"""
|
||||
Access to subgraph metadata
|
||||
"""
|
||||
_meta(block: Block_height): _Meta_
|
||||
}
|
||||
|
||||
type _Block_ {
|
||||
"""The hash of the block"""
|
||||
"""
|
||||
The hash of the block
|
||||
"""
|
||||
hash: Bytes
|
||||
"""The block number"""
|
||||
"""
|
||||
The block number
|
||||
"""
|
||||
number: Int!
|
||||
"""Integer representation of the timestamp stored in blocks for the chain"""
|
||||
"""
|
||||
Integer representation of the timestamp stored in blocks for the chain
|
||||
"""
|
||||
timestamp: Int
|
||||
}
|
||||
|
||||
"""The type for the top-level _meta field"""
|
||||
"""
|
||||
The type for the top-level _meta field
|
||||
"""
|
||||
type _Meta_ {
|
||||
"""
|
||||
Information about a specific subgraph block. The hash of the block
|
||||
will be null if the _meta field has a block constraint that asks for
|
||||
a block number. It will be filled if the _meta field has no block constraint
|
||||
and therefore asks for the latest block
|
||||
|
||||
"""
|
||||
block: _Block_!
|
||||
"""The deployment ID"""
|
||||
"""
|
||||
The deployment ID
|
||||
"""
|
||||
deployment: String!
|
||||
"""If `true`, the subgraph encountered indexing errors at some past block"""
|
||||
"""
|
||||
If `true`, the subgraph encountered indexing errors at some past block
|
||||
"""
|
||||
hasIndexingErrors: Boolean!
|
||||
}
|
||||
|
||||
enum _SubgraphErrorPolicy_ {
|
||||
"""Data will be returned even if the subgraph has indexing errors"""
|
||||
"""
|
||||
Data will be returned even if the subgraph has indexing errors
|
||||
"""
|
||||
allow
|
||||
"""
|
||||
If the subgraph has indexing errors, data will be omitted. The default.
|
||||
"""
|
||||
deny
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,8 +15,20 @@ directive @derivedFrom(field: String!) on FIELD_DEFINITION
|
||||
type Address {
|
||||
id: ID!
|
||||
address: Bytes!
|
||||
authOutgoing(skip: Int = 0, first: Int = 100, orderBy: Authentication_orderBy, orderDirection: OrderDirection, where: Authentication_filter): [Authentication!]
|
||||
authIncoming(skip: Int = 0, first: Int = 100, orderBy: Authentication_orderBy, orderDirection: OrderDirection, where: Authentication_filter): [Authentication!]
|
||||
authOutgoing(
|
||||
skip: Int = 0
|
||||
first: Int = 100
|
||||
orderBy: Authentication_orderBy
|
||||
orderDirection: OrderDirection
|
||||
where: Authentication_filter
|
||||
): [Authentication!]
|
||||
authIncoming(
|
||||
skip: Int = 0
|
||||
first: Int = 100
|
||||
orderBy: Authentication_orderBy
|
||||
orderDirection: OrderDirection
|
||||
where: Authentication_filter
|
||||
): [Authentication!]
|
||||
}
|
||||
|
||||
input Address_filter {
|
||||
@@ -36,7 +48,9 @@ input Address_filter {
|
||||
address_not_contains: Bytes
|
||||
authOutgoing_: Authentication_filter
|
||||
authIncoming_: Authentication_filter
|
||||
"""Filter for the block changed event."""
|
||||
"""
|
||||
Filter for the block changed event.
|
||||
"""
|
||||
_change_block: BlockChangedFilter
|
||||
}
|
||||
|
||||
@@ -128,7 +142,9 @@ input AuthData_filter {
|
||||
created_ends_with_nocase: String
|
||||
created_not_ends_with: String
|
||||
created_not_ends_with_nocase: String
|
||||
"""Filter for the block changed event."""
|
||||
"""
|
||||
Filter for the block changed event.
|
||||
"""
|
||||
_change_block: BlockChangedFilter
|
||||
}
|
||||
|
||||
@@ -207,7 +223,9 @@ input AuthStatus_filter {
|
||||
validationTime_ends_with_nocase: String
|
||||
validationTime_not_ends_with: String
|
||||
validationTime_not_ends_with_nocase: String
|
||||
"""Filter for the block changed event."""
|
||||
"""
|
||||
Filter for the block changed event.
|
||||
"""
|
||||
_change_block: BlockChangedFilter
|
||||
}
|
||||
|
||||
@@ -310,7 +328,9 @@ input Authentication_filter {
|
||||
created_ends_with_nocase: String
|
||||
created_not_ends_with: String
|
||||
created_not_ends_with_nocase: String
|
||||
"""Filter for the block changed event."""
|
||||
"""
|
||||
Filter for the block changed event.
|
||||
"""
|
||||
_change_block: BlockChangedFilter
|
||||
}
|
||||
|
||||
@@ -340,7 +360,9 @@ input Block_height {
|
||||
|
||||
scalar Bytes
|
||||
|
||||
"""Defines the order direction, either ascending or descending"""
|
||||
"""
|
||||
Defines the order direction, either ascending or descending
|
||||
"""
|
||||
enum OrderDirection {
|
||||
asc
|
||||
desc
|
||||
@@ -451,7 +473,9 @@ type Query {
|
||||
"""
|
||||
subgraphError: _SubgraphErrorPolicy_! = deny
|
||||
): [Address!]!
|
||||
"""Access to subgraph metadata"""
|
||||
"""
|
||||
Access to subgraph metadata
|
||||
"""
|
||||
_meta(block: Block_height): _Meta_
|
||||
}
|
||||
|
||||
@@ -560,40 +584,55 @@ type Subscription {
|
||||
"""
|
||||
subgraphError: _SubgraphErrorPolicy_! = deny
|
||||
): [Address!]!
|
||||
"""Access to subgraph metadata"""
|
||||
"""
|
||||
Access to subgraph metadata
|
||||
"""
|
||||
_meta(block: Block_height): _Meta_
|
||||
}
|
||||
|
||||
type _Block_ {
|
||||
"""The hash of the block"""
|
||||
"""
|
||||
The hash of the block
|
||||
"""
|
||||
hash: Bytes
|
||||
"""The block number"""
|
||||
"""
|
||||
The block number
|
||||
"""
|
||||
number: Int!
|
||||
"""Integer representation of the timestamp stored in blocks for the chain"""
|
||||
"""
|
||||
Integer representation of the timestamp stored in blocks for the chain
|
||||
"""
|
||||
timestamp: Int
|
||||
}
|
||||
|
||||
"""The type for the top-level _meta field"""
|
||||
"""
|
||||
The type for the top-level _meta field
|
||||
"""
|
||||
type _Meta_ {
|
||||
"""
|
||||
Information about a specific subgraph block. The hash of the block
|
||||
will be null if the _meta field has a block constraint that asks for
|
||||
a block number. It will be filled if the _meta field has no block constraint
|
||||
and therefore asks for the latest block
|
||||
|
||||
"""
|
||||
block: _Block_!
|
||||
"""The deployment ID"""
|
||||
"""
|
||||
The deployment ID
|
||||
"""
|
||||
deployment: String!
|
||||
"""If `true`, the subgraph encountered indexing errors at some past block"""
|
||||
"""
|
||||
If `true`, the subgraph encountered indexing errors at some past block
|
||||
"""
|
||||
hasIndexingErrors: Boolean!
|
||||
}
|
||||
|
||||
enum _SubgraphErrorPolicy_ {
|
||||
"""Data will be returned even if the subgraph has indexing errors"""
|
||||
"""
|
||||
Data will be returned even if the subgraph has indexing errors
|
||||
"""
|
||||
allow
|
||||
"""
|
||||
If the subgraph has indexing errors, data will be omitted. The default.
|
||||
"""
|
||||
deny
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"HashCheckVerfier": "0xF248E2ba728Dc6f8143bDC37226A2792e7c4bbc7",
|
||||
"OtpMerkleTreeVerifier": "0x5051B73E8E24a740863f61B6ff1FfB23d26e7A87",
|
||||
"ZkWalletFactory": "0x8D1d409C17a24CE271a0AFfa53Bf82b7cF304E7e"
|
||||
}
|
||||
"HashCheckVerfier": "0xF248E2ba728Dc6f8143bDC37226A2792e7c4bbc7",
|
||||
"OtpMerkleTreeVerifier": "0x5051B73E8E24a740863f61B6ff1FfB23d26e7A87",
|
||||
"ZkWalletFactory": "0x8D1d409C17a24CE271a0AFfa53Bf82b7cF304E7e"
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@ import { Navbar } from '..'
|
||||
import Head from 'next/head'
|
||||
import { useTheGraph } from '../../hooks/useTheGraph'
|
||||
|
||||
|
||||
export default function Layout(props: any) {
|
||||
|
||||
const walletAddress = "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
const walletAddress = '0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d'
|
||||
|
||||
const data = useTheGraph(walletAddress)
|
||||
|
||||
|
||||
@@ -128,9 +128,7 @@ const ModalVerifyTotp = (props: ModalVerifyTotpProps) => {
|
||||
<div className="mt-2">
|
||||
<p className="mb-5 text-md font-normal text-gray-500 dark:text-gray-300">
|
||||
{props.verified === true ? (
|
||||
<p>
|
||||
You have successfully verified your account
|
||||
</p>
|
||||
<p>You have successfully verified your account</p>
|
||||
) : (
|
||||
<p>Wrong code. Please try again.</p>
|
||||
)}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# GraphAPI
|
||||
|
||||
Steps:
|
||||
|
||||
1. File with the query `query.qraphql`
|
||||
2. Config file `.graphclientrc.yml` in root
|
||||
3. Install `@graphprotocol/client-cli` for dev
|
||||
@@ -11,7 +12,11 @@ Steps:
|
||||
```ts
|
||||
import React, { useEffect } from 'react'
|
||||
// we import types and typed-graphql document from the generated code (`..graphclient/`)
|
||||
import { ExampleQueryDocument, ExampleQueryQuery, execute } from '../.graphclient'
|
||||
import {
|
||||
ExampleQueryDocument,
|
||||
ExampleQueryQuery,
|
||||
execute,
|
||||
} from '../.graphclient'
|
||||
|
||||
function App() {
|
||||
const [data, setData] = React.useState<ExampleQueryQuery>()
|
||||
@@ -24,7 +29,11 @@ function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
<p>Graph Client Example</p>
|
||||
<textarea value={JSON.stringify(result.data, null, 2)} readOnly rows={25} />
|
||||
<textarea
|
||||
value={JSON.stringify(result.data, null, 2)}
|
||||
readOnly
|
||||
rows={25}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -54,4 +54,4 @@ query AddressAll($walletAddress: ID!) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,292 +1,282 @@
|
||||
/* global BigInt */
|
||||
module.exports = async function builder(code, options) {
|
||||
options = options || {}
|
||||
|
||||
options = options || {};
|
||||
const wasmModule = await WebAssembly.compile(code)
|
||||
|
||||
const wasmModule = await WebAssembly.compile(code);
|
||||
|
||||
let wc;
|
||||
|
||||
|
||||
const instance = await WebAssembly.instantiate(wasmModule, {
|
||||
runtime: {
|
||||
exceptionHandler: function (code) {
|
||||
let errStr;
|
||||
if (code === 1) {
|
||||
errStr = "Signal not found. ";
|
||||
} else if (code === 2) {
|
||||
errStr = "Too many signals set. ";
|
||||
} else if (code === 3) {
|
||||
errStr = "Signal already set. ";
|
||||
} else if (code === 4) {
|
||||
errStr = "Assert Failed. ";
|
||||
} else if (code === 5) {
|
||||
errStr = "Not enough memory. ";
|
||||
} else {
|
||||
errStr = "Unknown error\n";
|
||||
}
|
||||
// get error message from wasm
|
||||
errStr += getMessage();
|
||||
throw new Error(errStr);
|
||||
},
|
||||
showSharedRWMemory: function () {
|
||||
printSharedRWMemory();
|
||||
}
|
||||
let wc
|
||||
|
||||
const instance = await WebAssembly.instantiate(wasmModule, {
|
||||
runtime: {
|
||||
exceptionHandler: function (code) {
|
||||
let errStr
|
||||
if (code === 1) {
|
||||
errStr = 'Signal not found. '
|
||||
} else if (code === 2) {
|
||||
errStr = 'Too many signals set. '
|
||||
} else if (code === 3) {
|
||||
errStr = 'Signal already set. '
|
||||
} else if (code === 4) {
|
||||
errStr = 'Assert Failed. '
|
||||
} else if (code === 5) {
|
||||
errStr = 'Not enough memory. '
|
||||
} else {
|
||||
errStr = 'Unknown error\n'
|
||||
}
|
||||
});
|
||||
// get error message from wasm
|
||||
errStr += getMessage()
|
||||
throw new Error(errStr)
|
||||
},
|
||||
showSharedRWMemory: function () {
|
||||
printSharedRWMemory()
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const sanityCheck =
|
||||
options
|
||||
// options &&
|
||||
// (
|
||||
// options.sanityCheck ||
|
||||
// options.logGetSignal ||
|
||||
// options.logSetSignal ||
|
||||
// options.logStartComponent ||
|
||||
// options.logFinishComponent
|
||||
// );
|
||||
const sanityCheck = options
|
||||
// options &&
|
||||
// (
|
||||
// options.sanityCheck ||
|
||||
// options.logGetSignal ||
|
||||
// options.logSetSignal ||
|
||||
// options.logStartComponent ||
|
||||
// options.logFinishComponent
|
||||
// );
|
||||
|
||||
wc = new WitnessCalculator(instance, sanityCheck)
|
||||
return wc
|
||||
|
||||
wc = new WitnessCalculator(instance, sanityCheck);
|
||||
return wc;
|
||||
|
||||
function getMessage() {
|
||||
var message = "";
|
||||
var c = instance.exports.getMessageChar();
|
||||
while (c !== 0) {
|
||||
message += String.fromCharCode(c);
|
||||
c = instance.exports.getMessageChar();
|
||||
}
|
||||
return message;
|
||||
function getMessage() {
|
||||
var message = ''
|
||||
var c = instance.exports.getMessageChar()
|
||||
while (c !== 0) {
|
||||
message += String.fromCharCode(c)
|
||||
c = instance.exports.getMessageChar()
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
function printSharedRWMemory() {
|
||||
const shared_rw_memory_size = instance.exports.getFieldNumLen32();
|
||||
const arr = new Uint32Array(shared_rw_memory_size);
|
||||
for (let j = 0; j < shared_rw_memory_size; j++) {
|
||||
arr[shared_rw_memory_size - 1 - j] = instance.exports.readSharedRWMemory(j);
|
||||
}
|
||||
console.log(fromArray32(arr));
|
||||
function printSharedRWMemory() {
|
||||
const shared_rw_memory_size = instance.exports.getFieldNumLen32()
|
||||
const arr = new Uint32Array(shared_rw_memory_size)
|
||||
for (let j = 0; j < shared_rw_memory_size; j++) {
|
||||
arr[shared_rw_memory_size - 1 - j] =
|
||||
instance.exports.readSharedRWMemory(j)
|
||||
}
|
||||
|
||||
};
|
||||
console.log(fromArray32(arr))
|
||||
}
|
||||
}
|
||||
|
||||
class WitnessCalculator {
|
||||
constructor(instance, sanityCheck) {
|
||||
this.instance = instance;
|
||||
constructor(instance, sanityCheck) {
|
||||
this.instance = instance
|
||||
|
||||
this.version = this.instance.exports.getVersion();
|
||||
this.n32 = this.instance.exports.getFieldNumLen32();
|
||||
this.version = this.instance.exports.getVersion()
|
||||
this.n32 = this.instance.exports.getFieldNumLen32()
|
||||
|
||||
this.instance.exports.getRawPrime();
|
||||
const arr = new Array(this.n32);
|
||||
for (let i = 0; i < this.n32; i++) {
|
||||
arr[this.n32 - 1 - i] = this.instance.exports.readSharedRWMemory(i);
|
||||
}
|
||||
this.prime = fromArray32(arr);
|
||||
|
||||
this.witnessSize = this.instance.exports.getWitnessSize();
|
||||
|
||||
this.sanityCheck = sanityCheck;
|
||||
this.instance.exports.getRawPrime()
|
||||
const arr = new Array(this.n32)
|
||||
for (let i = 0; i < this.n32; i++) {
|
||||
arr[this.n32 - 1 - i] = this.instance.exports.readSharedRWMemory(i)
|
||||
}
|
||||
this.prime = fromArray32(arr)
|
||||
|
||||
circom_version() {
|
||||
return this.instance.exports.getVersion();
|
||||
}
|
||||
this.witnessSize = this.instance.exports.getWitnessSize()
|
||||
|
||||
async _doCalculateWitness(input, sanityCheck) {
|
||||
//input is assumed to be a map from signals to arrays of bigints
|
||||
this.sanityCheck = sanityCheck
|
||||
}
|
||||
|
||||
this.instance.exports.init((this.sanityCheck || sanityCheck) ? 1 : 0);
|
||||
const keys = Object.keys(input);
|
||||
var input_counter = 0;
|
||||
keys.forEach((k) => {
|
||||
const h = fnvHash(k);
|
||||
const hMSB = parseInt(h.slice(0, 8), 16);
|
||||
const hLSB = parseInt(h.slice(8, 16), 16);
|
||||
const fArr = flatArray(input[k]);
|
||||
for (let i = 0; i < fArr.length; i++) {
|
||||
const arrFr = toArray32(fArr[i], this.n32)
|
||||
for (let j = 0; j < this.n32; j++) {
|
||||
this.instance.exports.writeSharedRWMemory(j, arrFr[this.n32 - 1 - j]);
|
||||
}
|
||||
try {
|
||||
this.instance.exports.setInputSignal(hMSB, hLSB, i);
|
||||
input_counter++;
|
||||
} catch (err) {
|
||||
// console.log(`After adding signal ${i} of ${k}`)
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
circom_version() {
|
||||
return this.instance.exports.getVersion()
|
||||
}
|
||||
|
||||
});
|
||||
if (input_counter < this.instance.exports.getInputSize()) {
|
||||
throw new Error(`Not all inputs have been set. Only ${input_counter} out of ${this.instance.exports.getInputSize()}`);
|
||||
}
|
||||
}
|
||||
async _doCalculateWitness(input, sanityCheck) {
|
||||
//input is assumed to be a map from signals to arrays of bigints
|
||||
|
||||
async calculateWitness(input, sanityCheck) {
|
||||
|
||||
const w = [];
|
||||
|
||||
await this._doCalculateWitness(input, sanityCheck);
|
||||
|
||||
for (let i = 0; i < this.witnessSize; i++) {
|
||||
this.instance.exports.getWitness(i);
|
||||
const arr = new Uint32Array(this.n32);
|
||||
for (let j = 0; j < this.n32; j++) {
|
||||
arr[this.n32 - 1 - j] = this.instance.exports.readSharedRWMemory(j);
|
||||
}
|
||||
w.push(fromArray32(arr));
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
|
||||
async calculateBinWitness(input, sanityCheck) {
|
||||
|
||||
const buff32 = new Uint32Array(this.witnessSize * this.n32);
|
||||
const buff = new Uint8Array(buff32.buffer);
|
||||
await this._doCalculateWitness(input, sanityCheck);
|
||||
|
||||
for (let i = 0; i < this.witnessSize; i++) {
|
||||
this.instance.exports.getWitness(i);
|
||||
const pos = i * this.n32;
|
||||
for (let j = 0; j < this.n32; j++) {
|
||||
buff32[pos + j] = this.instance.exports.readSharedRWMemory(j);
|
||||
}
|
||||
}
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
||||
async calculateWTNSBin(input, sanityCheck) {
|
||||
|
||||
const buff32 = new Uint32Array(this.witnessSize * this.n32 + this.n32 + 11);
|
||||
|
||||
const buff = new Uint8Array(buff32.buffer);
|
||||
await this._doCalculateWitness(input, sanityCheck);
|
||||
|
||||
//"wtns"
|
||||
buff[0] = "w".charCodeAt(0)
|
||||
buff[1] = "t".charCodeAt(0)
|
||||
buff[2] = "n".charCodeAt(0)
|
||||
buff[3] = "s".charCodeAt(0)
|
||||
|
||||
//version 2
|
||||
buff32[1] = 2;
|
||||
|
||||
//number of sections: 2
|
||||
buff32[2] = 2;
|
||||
|
||||
//id section 1
|
||||
buff32[3] = 1;
|
||||
|
||||
const n8 = this.n32 * 4;
|
||||
//id section 1 length in 64bytes
|
||||
const idSection1length = 8 + n8;
|
||||
const idSection1lengthHex = idSection1length.toString(16);
|
||||
buff32[4] = parseInt(idSection1lengthHex.slice(0, 8), 16);
|
||||
buff32[5] = parseInt(idSection1lengthHex.slice(8, 16), 16);
|
||||
|
||||
//this.n32
|
||||
buff32[6] = n8;
|
||||
|
||||
//prime number
|
||||
this.instance.exports.getRawPrime();
|
||||
|
||||
var pos = 7;
|
||||
this.instance.exports.init(this.sanityCheck || sanityCheck ? 1 : 0)
|
||||
const keys = Object.keys(input)
|
||||
var input_counter = 0
|
||||
keys.forEach((k) => {
|
||||
const h = fnvHash(k)
|
||||
const hMSB = parseInt(h.slice(0, 8), 16)
|
||||
const hLSB = parseInt(h.slice(8, 16), 16)
|
||||
const fArr = flatArray(input[k])
|
||||
for (let i = 0; i < fArr.length; i++) {
|
||||
const arrFr = toArray32(fArr[i], this.n32)
|
||||
for (let j = 0; j < this.n32; j++) {
|
||||
buff32[pos + j] = this.instance.exports.readSharedRWMemory(j);
|
||||
this.instance.exports.writeSharedRWMemory(j, arrFr[this.n32 - 1 - j])
|
||||
}
|
||||
pos += this.n32;
|
||||
|
||||
// witness size
|
||||
buff32[pos] = this.witnessSize;
|
||||
pos++;
|
||||
|
||||
//id section 2
|
||||
buff32[pos] = 2;
|
||||
pos++;
|
||||
|
||||
// section 2 length
|
||||
const idSection2length = n8 * this.witnessSize;
|
||||
const idSection2lengthHex = idSection2length.toString(16);
|
||||
buff32[pos] = parseInt(idSection2lengthHex.slice(0, 8), 16);
|
||||
buff32[pos + 1] = parseInt(idSection2lengthHex.slice(8, 16), 16);
|
||||
|
||||
pos += 2;
|
||||
for (let i = 0; i < this.witnessSize; i++) {
|
||||
this.instance.exports.getWitness(i);
|
||||
for (let j = 0; j < this.n32; j++) {
|
||||
buff32[pos + j] = this.instance.exports.readSharedRWMemory(j);
|
||||
}
|
||||
pos += this.n32;
|
||||
try {
|
||||
this.instance.exports.setInputSignal(hMSB, hLSB, i)
|
||||
input_counter++
|
||||
} catch (err) {
|
||||
// console.log(`After adding signal ${i} of ${k}`)
|
||||
throw new Error(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
if (input_counter < this.instance.exports.getInputSize()) {
|
||||
throw new Error(
|
||||
`Not all inputs have been set. Only ${input_counter} out of ${this.instance.exports.getInputSize()}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return buff;
|
||||
async calculateWitness(input, sanityCheck) {
|
||||
const w = []
|
||||
|
||||
await this._doCalculateWitness(input, sanityCheck)
|
||||
|
||||
for (let i = 0; i < this.witnessSize; i++) {
|
||||
this.instance.exports.getWitness(i)
|
||||
const arr = new Uint32Array(this.n32)
|
||||
for (let j = 0; j < this.n32; j++) {
|
||||
arr[this.n32 - 1 - j] = this.instance.exports.readSharedRWMemory(j)
|
||||
}
|
||||
w.push(fromArray32(arr))
|
||||
}
|
||||
|
||||
}
|
||||
return w
|
||||
}
|
||||
|
||||
async calculateBinWitness(input, sanityCheck) {
|
||||
const buff32 = new Uint32Array(this.witnessSize * this.n32)
|
||||
const buff = new Uint8Array(buff32.buffer)
|
||||
await this._doCalculateWitness(input, sanityCheck)
|
||||
|
||||
for (let i = 0; i < this.witnessSize; i++) {
|
||||
this.instance.exports.getWitness(i)
|
||||
const pos = i * this.n32
|
||||
for (let j = 0; j < this.n32; j++) {
|
||||
buff32[pos + j] = this.instance.exports.readSharedRWMemory(j)
|
||||
}
|
||||
}
|
||||
|
||||
return buff
|
||||
}
|
||||
|
||||
async calculateWTNSBin(input, sanityCheck) {
|
||||
const buff32 = new Uint32Array(this.witnessSize * this.n32 + this.n32 + 11)
|
||||
|
||||
const buff = new Uint8Array(buff32.buffer)
|
||||
await this._doCalculateWitness(input, sanityCheck)
|
||||
|
||||
//"wtns"
|
||||
buff[0] = 'w'.charCodeAt(0)
|
||||
buff[1] = 't'.charCodeAt(0)
|
||||
buff[2] = 'n'.charCodeAt(0)
|
||||
buff[3] = 's'.charCodeAt(0)
|
||||
|
||||
//version 2
|
||||
buff32[1] = 2
|
||||
|
||||
//number of sections: 2
|
||||
buff32[2] = 2
|
||||
|
||||
//id section 1
|
||||
buff32[3] = 1
|
||||
|
||||
const n8 = this.n32 * 4
|
||||
//id section 1 length in 64bytes
|
||||
const idSection1length = 8 + n8
|
||||
const idSection1lengthHex = idSection1length.toString(16)
|
||||
buff32[4] = parseInt(idSection1lengthHex.slice(0, 8), 16)
|
||||
buff32[5] = parseInt(idSection1lengthHex.slice(8, 16), 16)
|
||||
|
||||
//this.n32
|
||||
buff32[6] = n8
|
||||
|
||||
//prime number
|
||||
this.instance.exports.getRawPrime()
|
||||
|
||||
var pos = 7
|
||||
for (let j = 0; j < this.n32; j++) {
|
||||
buff32[pos + j] = this.instance.exports.readSharedRWMemory(j)
|
||||
}
|
||||
pos += this.n32
|
||||
|
||||
// witness size
|
||||
buff32[pos] = this.witnessSize
|
||||
pos++
|
||||
|
||||
//id section 2
|
||||
buff32[pos] = 2
|
||||
pos++
|
||||
|
||||
// section 2 length
|
||||
const idSection2length = n8 * this.witnessSize
|
||||
const idSection2lengthHex = idSection2length.toString(16)
|
||||
buff32[pos] = parseInt(idSection2lengthHex.slice(0, 8), 16)
|
||||
buff32[pos + 1] = parseInt(idSection2lengthHex.slice(8, 16), 16)
|
||||
|
||||
pos += 2
|
||||
for (let i = 0; i < this.witnessSize; i++) {
|
||||
this.instance.exports.getWitness(i)
|
||||
for (let j = 0; j < this.n32; j++) {
|
||||
buff32[pos + j] = this.instance.exports.readSharedRWMemory(j)
|
||||
}
|
||||
pos += this.n32
|
||||
}
|
||||
|
||||
return buff
|
||||
}
|
||||
}
|
||||
|
||||
function toArray32(s, size) {
|
||||
const res = []; //new Uint32Array(size); //has no unshift
|
||||
let rem = BigInt(s);
|
||||
const radix = BigInt(0x100000000);
|
||||
while (rem) {
|
||||
res.unshift(Number(rem % radix));
|
||||
rem = rem / radix;
|
||||
const res = [] //new Uint32Array(size); //has no unshift
|
||||
let rem = BigInt(s)
|
||||
const radix = BigInt(0x100000000)
|
||||
while (rem) {
|
||||
res.unshift(Number(rem % radix))
|
||||
rem = rem / radix
|
||||
}
|
||||
if (size) {
|
||||
var i = size - res.length
|
||||
while (i > 0) {
|
||||
res.unshift(0)
|
||||
i--
|
||||
}
|
||||
if (size) {
|
||||
var i = size - res.length;
|
||||
while (i > 0) {
|
||||
res.unshift(0);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
function fromArray32(arr) { //returns a BigInt
|
||||
var res = BigInt(0);
|
||||
const radix = BigInt(0x100000000);
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
res = res * radix + BigInt(arr[i]);
|
||||
}
|
||||
return res;
|
||||
function fromArray32(arr) {
|
||||
//returns a BigInt
|
||||
var res = BigInt(0)
|
||||
const radix = BigInt(0x100000000)
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
res = res * radix + BigInt(arr[i])
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
function flatArray(a) {
|
||||
var res = [];
|
||||
fillArray(res, a);
|
||||
return res;
|
||||
var res = []
|
||||
fillArray(res, a)
|
||||
return res
|
||||
|
||||
function fillArray(res, a) {
|
||||
if (Array.isArray(a)) {
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
fillArray(res, a[i]);
|
||||
}
|
||||
} else {
|
||||
res.push(a);
|
||||
}
|
||||
function fillArray(res, a) {
|
||||
if (Array.isArray(a)) {
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
fillArray(res, a[i])
|
||||
}
|
||||
} else {
|
||||
res.push(a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function fnvHash(str) {
|
||||
let uint64_max = 18446744073709551616n;
|
||||
// let uint64_max = BigInt(2) ** BigInt(64);
|
||||
let hash = BigInt("0xCBF29CE484222325");
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
hash ^= BigInt(str[i].charCodeAt());
|
||||
hash *= BigInt(0x100000001B3);
|
||||
hash %= uint64_max;
|
||||
}
|
||||
let shash = hash.toString(16);
|
||||
let n = 16 - shash.length;
|
||||
shash = '0'.repeat(n).concat(shash);
|
||||
return shash;
|
||||
}
|
||||
let uint64_max = 18446744073709551616n
|
||||
// let uint64_max = BigInt(2) ** BigInt(64);
|
||||
let hash = BigInt('0xCBF29CE484222325')
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
hash ^= BigInt(str[i].charCodeAt())
|
||||
hash *= BigInt(0x100000001b3)
|
||||
hash %= uint64_max
|
||||
}
|
||||
let shash = hash.toString(16)
|
||||
let n = 16 - shash.length
|
||||
shash = '0'.repeat(n).concat(shash)
|
||||
return shash
|
||||
}
|
||||
|
||||
@@ -4,11 +4,9 @@ import { Web3File } from 'web3.storage/dist/src/lib/interface'
|
||||
const token = process.env.NEXT_PUBLIC_WEB3STORAGE
|
||||
|
||||
function getClient(): Web3Storage | null {
|
||||
|
||||
if (token) {
|
||||
const client = new Web3Storage({ token })
|
||||
return client
|
||||
|
||||
} else {
|
||||
console.error('Web3Storage api token required!')
|
||||
return null
|
||||
@@ -33,18 +31,18 @@ export const ipfsUpload = async (fileToUpload: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// function to fetch from web3Storage over IPFS gateway
|
||||
export const ipfsFetch = async (cid: string): Promise<Web3File[] | undefined> => {
|
||||
|
||||
export const ipfsFetch = async (
|
||||
cid: string
|
||||
): Promise<Web3File[] | undefined> => {
|
||||
const client = getClient()
|
||||
if (client) {
|
||||
const res = (await client?.get(cid))
|
||||
const res = await client?.get(cid)
|
||||
const files = await res?.files()
|
||||
|
||||
if (files) {
|
||||
for (const file of files) {
|
||||
console.log(`${file.cid} ${file.name} ${file.size}`);
|
||||
console.log(`${file.cid} ${file.name} ${file.size}`)
|
||||
}
|
||||
}
|
||||
return files
|
||||
|
||||
@@ -65,11 +65,13 @@ export async function generateInput(
|
||||
) {
|
||||
// let hashes = localStorage.getItem('OTPhashes')?.split(',').map(BigInt)
|
||||
// console.log(hashes)
|
||||
const hashesString = await decryptOrSignMetamask(encryptedHashes, 'eth_decrypt')
|
||||
const hashesString = await decryptOrSignMetamask(
|
||||
encryptedHashes,
|
||||
'eth_decrypt'
|
||||
)
|
||||
const hashes = hashesString?.split(',').map(BigInt)
|
||||
|
||||
if (hashes) {
|
||||
|
||||
let poseidon = await buildPoseidon()
|
||||
|
||||
let currentTime = Math.floor((Date.now() - 5000) / 30000) * 30000 // 3lLobo: Gave it a 5sec backwards buffer
|
||||
|
||||
@@ -1,130 +1,130 @@
|
||||
{
|
||||
"data": {
|
||||
"address": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"authIncoming": [
|
||||
{
|
||||
"created": "1663603102",
|
||||
"requestId": "1",
|
||||
"id": "1",
|
||||
"authData": {
|
||||
"created": "1663603325",
|
||||
"genTime": "111111",
|
||||
"totp5": "12345",
|
||||
"id": "1_data",
|
||||
"totp6Hash": "0x4a438cf911dc63bd7d53c1be977516e82f4d8f19b950d72d6730d4717709eae1"
|
||||
},
|
||||
"requestee": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"requestor": {
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"status": {
|
||||
"validationTime": null,
|
||||
"isValid": false,
|
||||
"id": "1_status",
|
||||
"hasResponse": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"created": "1663603102",
|
||||
"requestId": "0",
|
||||
"id": "0",
|
||||
"authData": {
|
||||
"created": "1663603342",
|
||||
"genTime": "111111",
|
||||
"totp5": "12345",
|
||||
"id": "0_data",
|
||||
"totp6Hash": "0x5a438cf911dc63bd7d53c1be977516e82f4d8f19b950d72d6730d4717709eae1"
|
||||
},
|
||||
"requestee": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"requestor": {
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"status": {
|
||||
"validationTime": null,
|
||||
"isValid": false,
|
||||
"id": "0_status",
|
||||
"hasResponse": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"authOutgoing": [
|
||||
{
|
||||
"authData": null,
|
||||
"created": "1663603122",
|
||||
"id": "2",
|
||||
"requestId": "2",
|
||||
"requestee": {
|
||||
"id": "0x5e9607ee52286732a5e3a0fc57df367bcb8adaa5",
|
||||
"address": "0x5e9607ee52286732a5e3a0fc57df367bcb8adaa5"
|
||||
},
|
||||
"requestor": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"status": null
|
||||
},
|
||||
{
|
||||
"authData": {
|
||||
"totp6Hash": "0x4a438cf911dc63bd7d53c1be977516e82f4d8f19b950d72d6730d4717709eae1",
|
||||
"totp5": "12345",
|
||||
"id": "1_data",
|
||||
"genTime": "111111",
|
||||
"created": "1663603325"
|
||||
},
|
||||
"created": "1663603102",
|
||||
"id": "1",
|
||||
"requestId": "1",
|
||||
"requestee": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"requestor": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"status": {
|
||||
"validationTime": null,
|
||||
"isValid": false,
|
||||
"id": "1_status",
|
||||
"hasResponse": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"authData": {
|
||||
"totp6Hash": "0x5a438cf911dc63bd7d53c1be977516e82f4d8f19b950d72d6730d4717709eae1",
|
||||
"totp5": "12345",
|
||||
"id": "0_data",
|
||||
"genTime": "111111",
|
||||
"created": "1663603342"
|
||||
},
|
||||
"created": "1663603102",
|
||||
"id": "0",
|
||||
"requestId": "0",
|
||||
"requestee": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"requestor": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"status": {
|
||||
"validationTime": null,
|
||||
"isValid": false,
|
||||
"id": "0_status",
|
||||
"hasResponse": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
"address": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"authIncoming": [
|
||||
{
|
||||
"created": "1663603102",
|
||||
"requestId": "1",
|
||||
"id": "1",
|
||||
"authData": {
|
||||
"created": "1663603325",
|
||||
"genTime": "111111",
|
||||
"totp5": "12345",
|
||||
"id": "1_data",
|
||||
"totp6Hash": "0x4a438cf911dc63bd7d53c1be977516e82f4d8f19b950d72d6730d4717709eae1"
|
||||
},
|
||||
"requestee": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"requestor": {
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"status": {
|
||||
"validationTime": null,
|
||||
"isValid": false,
|
||||
"id": "1_status",
|
||||
"hasResponse": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"created": "1663603102",
|
||||
"requestId": "0",
|
||||
"id": "0",
|
||||
"authData": {
|
||||
"created": "1663603342",
|
||||
"genTime": "111111",
|
||||
"totp5": "12345",
|
||||
"id": "0_data",
|
||||
"totp6Hash": "0x5a438cf911dc63bd7d53c1be977516e82f4d8f19b950d72d6730d4717709eae1"
|
||||
},
|
||||
"requestee": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"requestor": {
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"status": {
|
||||
"validationTime": null,
|
||||
"isValid": false,
|
||||
"id": "0_status",
|
||||
"hasResponse": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"authOutgoing": [
|
||||
{
|
||||
"authData": null,
|
||||
"created": "1663603122",
|
||||
"id": "2",
|
||||
"requestId": "2",
|
||||
"requestee": {
|
||||
"id": "0x5e9607ee52286732a5e3a0fc57df367bcb8adaa5",
|
||||
"address": "0x5e9607ee52286732a5e3a0fc57df367bcb8adaa5"
|
||||
},
|
||||
"requestor": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"status": null
|
||||
},
|
||||
{
|
||||
"authData": {
|
||||
"totp6Hash": "0x4a438cf911dc63bd7d53c1be977516e82f4d8f19b950d72d6730d4717709eae1",
|
||||
"totp5": "12345",
|
||||
"id": "1_data",
|
||||
"genTime": "111111",
|
||||
"created": "1663603325"
|
||||
},
|
||||
"created": "1663603102",
|
||||
"id": "1",
|
||||
"requestId": "1",
|
||||
"requestee": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"requestor": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"status": {
|
||||
"validationTime": null,
|
||||
"isValid": false,
|
||||
"id": "1_status",
|
||||
"hasResponse": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"authData": {
|
||||
"totp6Hash": "0x5a438cf911dc63bd7d53c1be977516e82f4d8f19b950d72d6730d4717709eae1",
|
||||
"totp5": "12345",
|
||||
"id": "0_data",
|
||||
"genTime": "111111",
|
||||
"created": "1663603342"
|
||||
},
|
||||
"created": "1663603102",
|
||||
"id": "0",
|
||||
"requestId": "0",
|
||||
"requestee": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"requestor": {
|
||||
"id": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d",
|
||||
"address": "0x369551e7c1d29756e18ba4ed7f85f2e6663e1e8d"
|
||||
},
|
||||
"status": {
|
||||
"validationTime": null,
|
||||
"isValid": false,
|
||||
"id": "0_status",
|
||||
"hasResponse": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,40 +3,49 @@ import { useViewerRecord } from '@self.id/react'
|
||||
import { EthereumAuthProvider } from '@self.id/web'
|
||||
import { Dispatch, SetStateAction, useEffect, useState } from 'react'
|
||||
|
||||
|
||||
async function connectCeramic({ address, connect, setConnecting }: { address: string, connect: any, setConnecting: Dispatch<SetStateAction<boolean>> }) {
|
||||
async function connectCeramic({
|
||||
address,
|
||||
connect,
|
||||
setConnecting,
|
||||
}: {
|
||||
address: string
|
||||
connect: any
|
||||
setConnecting: Dispatch<SetStateAction<boolean>>
|
||||
}) {
|
||||
// Assumes there is an injected `window.ethereum` provider
|
||||
const provider = await new EthereumAuthProvider(window.ethereum, address)
|
||||
setConnecting(() => true)
|
||||
connect(provider).then((res: any) => {
|
||||
console.warn("ceramic connecting: ", res)
|
||||
console.warn('ceramic connecting: ', res)
|
||||
setConnecting(() => false)
|
||||
})
|
||||
}
|
||||
|
||||
// A hook combining login and fetching data. Gets triggered when a eth address is passed.
|
||||
export function useCeramic(address: string | null): {
|
||||
ceramicData: { content: any, set: Dispatch<any> },
|
||||
ceramicData: { content: any; set: Dispatch<any> }
|
||||
ceramicStatus: string
|
||||
// setCeramicAddress: Dispatch<SetStateAction<string | null | undefined>>
|
||||
} {
|
||||
const [connection, connect, disconnect] = useViewerConnection()
|
||||
const [connecting, setConnecting] = useState<boolean>(false)
|
||||
const record = useViewerRecord('kjzl6cwe1jw149ljmroydckks0ihhv2qel7wpyrold7qs3bgp765siz8234jqge')
|
||||
const record = useViewerRecord(
|
||||
'kjzl6cwe1jw149ljmroydckks0ihhv2qel7wpyrold7qs3bgp765siz8234jqge'
|
||||
)
|
||||
|
||||
// promt user to connect to ceramic if it's available and not yet connected
|
||||
if (connection.status !== 'connected' && address && !connecting) {
|
||||
connectCeramic({
|
||||
address,
|
||||
connect,
|
||||
setConnecting
|
||||
setConnecting,
|
||||
})
|
||||
}
|
||||
|
||||
const [content, setContent] = useState<any>()
|
||||
const [isFetched, setIsFetched] = useState<boolean>(false)
|
||||
|
||||
// sets the local state to the fetched value once it is available
|
||||
// sets the local state to the fetched value once it is available
|
||||
useEffect(() => {
|
||||
if (record.content && !isFetched) {
|
||||
setContent(() => record.content)
|
||||
@@ -44,14 +53,17 @@ export function useCeramic(address: string | null): {
|
||||
}
|
||||
}, [isFetched, record.content])
|
||||
|
||||
// updates the ceramic record with the local state.
|
||||
// updates the ceramic record with the local state.
|
||||
useEffect(() => {
|
||||
if (isFetched && (record.content !== content) && record.set) {
|
||||
if (isFetched && record.content !== content && record.set) {
|
||||
record.set(content)
|
||||
}
|
||||
}, [content, isFetched])
|
||||
|
||||
return { ceramicData: { content, set: setContent }, ceramicStatus: connection.status }
|
||||
return {
|
||||
ceramicData: { content, set: setContent },
|
||||
ceramicStatus: connection.status,
|
||||
}
|
||||
}
|
||||
|
||||
// Excerpt from the docs. The data is stored in record.content. To write use record.set or record.merge.
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { AddressAllDocument, AddressAllQuery, execute } from '../.graphclient'
|
||||
|
||||
|
||||
// Hook to interact with the TotpAuth subgraph
|
||||
// An example of the returned data can be found in ./exampleResult.json
|
||||
export function useTheGraph(walletAddress: string) {
|
||||
|
||||
const [result, setResult] = useState<AddressAllQuery>()
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
async function getGraphData() {
|
||||
const gqlRes = await execute(
|
||||
AddressAllDocument, { walletAddress: walletAddress.toLowerCase() })
|
||||
const gqlRes = await execute(AddressAllDocument, {
|
||||
walletAddress: walletAddress.toLowerCase(),
|
||||
})
|
||||
|
||||
setResult(gqlRes.data)
|
||||
}
|
||||
@@ -20,8 +18,7 @@ export function useTheGraph(walletAddress: string) {
|
||||
if (walletAddress?.length == 42) {
|
||||
getGraphData()
|
||||
}
|
||||
}, [walletAddress])
|
||||
|
||||
}, [walletAddress]);
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
require("dotenv").config()
|
||||
require('dotenv').config()
|
||||
const nextConfig = {
|
||||
reactStrictMode: true,
|
||||
swcMinify: true,
|
||||
@@ -8,29 +8,38 @@ const nextConfig = {
|
||||
},
|
||||
webpack: (config) => {
|
||||
config.resolve.fallback = { fs: false }
|
||||
config.resolve.extensions = ['*', '.mjs', '.js', 'jsx', '.ts', '.tsx', '.json']
|
||||
config.module.rules.push(
|
||||
{
|
||||
test: /\.mjs$/,
|
||||
include: /node_modules/,
|
||||
type: 'javascript/auto'
|
||||
})
|
||||
|
||||
config.resolve.extensions = [
|
||||
'*',
|
||||
'.mjs',
|
||||
'.js',
|
||||
'jsx',
|
||||
'.ts',
|
||||
'.tsx',
|
||||
'.json',
|
||||
]
|
||||
config.module.rules.push({
|
||||
test: /\.mjs$/,
|
||||
include: /node_modules/,
|
||||
type: 'javascript/auto',
|
||||
})
|
||||
|
||||
return config
|
||||
},
|
||||
env: {
|
||||
API_KEY: process.env.API_KEY
|
||||
API_KEY: process.env.API_KEY,
|
||||
},
|
||||
async headers() {
|
||||
return [
|
||||
{
|
||||
source: "/:path*",
|
||||
source: '/:path*',
|
||||
headers: [
|
||||
{ key: "Access-Control-Allow-Origin", value: "*" },
|
||||
{ key: "Access-Control-Allow-Methods", value: "GET,OPTIONS,PATCH,DELETE,POST,PUT" },
|
||||
]
|
||||
}
|
||||
{ key: 'Access-Control-Allow-Origin', value: '*' },
|
||||
{
|
||||
key: 'Access-Control-Allow-Methods',
|
||||
value: 'GET,OPTIONS,PATCH,DELETE,POST,PUT',
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
@@ -7,30 +7,27 @@ import { useState, SetStateAction } from 'react'
|
||||
import { useCeramic } from '../hooks/useCeramic'
|
||||
import { recoverAddress } from 'ethers/lib/utils'
|
||||
|
||||
|
||||
function demoEncryption() {
|
||||
|
||||
const [ceramicAddress, setCeramicAddress] = useState()
|
||||
const { activateBrowserWallet, library } = useEthers()
|
||||
const { ceramicData, ceramicStatus } = useCeramic(ceramicAddress)
|
||||
|
||||
useEffect(() => {
|
||||
if (!ceramicAddress) {
|
||||
setCeramicAddress("0x369551E7c1D29756e18BA4Ed7f85f2E6663e1e8d")
|
||||
setCeramicAddress('0x369551E7c1D29756e18BA4Ed7f85f2E6663e1e8d')
|
||||
}
|
||||
console.log("Record: ", ceramicData)
|
||||
console.log("ceramicStatus", ceramicStatus)
|
||||
console.log('Record: ', ceramicData)
|
||||
console.log('ceramicStatus', ceramicStatus)
|
||||
|
||||
// @danial How to read the data
|
||||
if (ceramicData.content) {
|
||||
console.log("Read the hashes: ", ceramicData.content.MerkleTree)
|
||||
console.log('Read the hashes: ', ceramicData.content.MerkleTree)
|
||||
}
|
||||
|
||||
}, [ceramicData, ceramicStatus])
|
||||
|
||||
const topSecret = "TopSecret🔐"
|
||||
const topSecret = 'TopSecret🔐'
|
||||
const [text, setText] = useState(topSecret)
|
||||
const [buttonText, setButtonText] = useState("Encrypt")
|
||||
const [buttonText, setButtonText] = useState('Encrypt')
|
||||
|
||||
useEffect(() => {
|
||||
activateBrowserWallet()
|
||||
@@ -42,22 +39,16 @@ function demoEncryption() {
|
||||
<>
|
||||
<div className="flex justify-center w-full max-w-7xl lg:px-8">
|
||||
<div className="w-full flex flex-col justify-center place-items-center bg-white ring-1 ring-zinc-100 dark:bg-zinc-900 dark:ring-zinc-300/20">
|
||||
|
||||
<button
|
||||
onClick={() => {
|
||||
signMsg(topSecret, setText, setButtonText, ceramicData)
|
||||
// prepareMerkleTree()
|
||||
}
|
||||
}
|
||||
|
||||
className=' w-fit px-6 py-1 bg-violet-400 dark:bg-violet-500 hover:bg-violet-500 rounded-3xl m-3'
|
||||
}}
|
||||
className=" w-fit px-6 py-1 bg-violet-400 dark:bg-violet-500 hover:bg-violet-500 rounded-3xl m-3"
|
||||
>
|
||||
{buttonText}
|
||||
</button>
|
||||
<div
|
||||
className='m-3 truncate max-w-3xl'>
|
||||
{text}
|
||||
</div>
|
||||
<div className="m-3 truncate max-w-3xl">{text}</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
@@ -66,24 +57,21 @@ function demoEncryption() {
|
||||
|
||||
// Using EPI-712 to sign the msg. https://eips.ethereum.org/EIPS/eip-712
|
||||
async function signMsg(msg, setText, setButtonText, ceramicData) {
|
||||
|
||||
var encMsg = await encryptMetamask(msg)
|
||||
setText(JSON.parse(encMsg).ciphertext)
|
||||
setButtonText("Decrypt")
|
||||
setButtonText('Decrypt')
|
||||
|
||||
// write data to ceramic. The {MerkleTree: string} schema is required, otherwise it will throw an error
|
||||
ceramicData.set({ MerkleTree: encMsg })
|
||||
|
||||
const restoredMsg = await decryptOrSignMetamask(encMsg, 'eth_decrypt')
|
||||
setText(restoredMsg)
|
||||
setButtonText("SignV4")
|
||||
setButtonText('SignV4')
|
||||
|
||||
const res = await decryptOrSignMetamask(restoredMsg, 'eth_signTypedData_v4')
|
||||
console.log("Signed Data:", res)
|
||||
console.log('Signed Data:', res)
|
||||
setText(res)
|
||||
setButtonText("Encrypt")
|
||||
setButtonText('Encrypt')
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default demoEncryption
|
||||
export default demoEncryption
|
||||
|
||||
Reference in New Issue
Block a user