Skip to content

Commit

Permalink
Merge pull request #17 from hollow-leaf/feat/uploadFileCoin
Browse files Browse the repository at this point in the history
feat: upload filecoin
  • Loading branch information
kidneyweakx authored Aug 23, 2023
2 parents 56e51f9 + 53cecba commit 194d8ba
Show file tree
Hide file tree
Showing 6 changed files with 396 additions and 44 deletions.
2 changes: 2 additions & 0 deletions packages/helper/.env.exmaple
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
LIGHT_HOUSE_API=lighthouseapi
PRIVATE_KEY=priv_key
1 change: 1 addition & 0 deletions packages/helper/circuit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"conv2d_weights": ["-333429997568", "187689779200", "-188812001280", "337814749184", "75445903360", "-323181936640", "-355153149952", "337260052480", "-232818655232", "-103362535424", "-43360043008", "-158397759488", "347956281344", "-346289012736", "1715365760", "-65816788992", "149287813120", "339770867712", "301016743936", "-23415363584", "25395761152", "-82288738304", "-20345393152", "242068029440", "-168263516160", "62386991104", "167882997760", "-386649358336", "163811213312", "-15747522560", "254475976704", "-103496376320", "221910794240", "525326024704", "-58888212480", "-128811491328"], "conv2d_bias": ["0", "0", "0", "0"], "batch_normalization_a": ["62195867648", "60894838784", "100129497088", "121842089984"], "batch_normalization_b": ["-2135494677567578111475712", "-2056629514390510971650048", "-804851692119872394756096", "-814392766088840394833920"], "dense_weights": ["341283766272", "-774646136832", "-269562658816", "-864747585536", "482132033536", "-504964939776", "-328049131520", "1071110094848"], "dense_bias": ["-64280785620212568611055265791025422761450339341454056357888", "64280800521373761944703612542526173670625057468181515337728"]}
49 changes: 26 additions & 23 deletions packages/helper/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
{
"name": "helper",
"version": "0.0.0",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"export": {
".": "./dist"
},
"scripts": {
"build": "tsup src/index.ts --format cjs --dts",
"dev": "npm run build -- --watch"
},
"dependencies": {
"tsconfig": "workspace:*"
},
"devDependencies": {
"tsconfig": "workspace:*",
"typescript": "^5.0.4",
"tsup": "^6.1.3"
},
"publishConfig": {
"access": "public"
}
"name": "helper",
"version": "0.0.0",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"export": {
".": "./dist"
},
"scripts": {
"build": "tsup src/index.ts --format cjs --dts",
"dev": "npm run build -- --watch"
},
"dependencies": {
"@lighthouse-web3/sdk": "^0.2.6",
"ethers": "^5.7.0",
"tsconfig": "workspace:*"
},
"devDependencies": {
"dotenv": "^16.3.1",
"ts-node": "^10.9.1",
"tsconfig": "workspace:*",
"tsup": "^6.1.3",
"typescript": "^5.0.4"
},
"publishConfig": {
"access": "public"
}
}
3 changes: 2 additions & 1 deletion packages/helper/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './lighthouse/lighthouse'
export const sleep = (time: number) => new Promise(resolve => setTimeout(resolve, time))

export const formatAddress = (address: string) => {
Expand All @@ -11,4 +12,4 @@ export const formatAddress = (address: string) => {
const suffix = address.slice(-6); // Get the last six characters
return `${prefix}...${suffix}`; // Combine the first six, ..., and last six characters
}
}
}
47 changes: 47 additions & 0 deletions packages/helper/src/lighthouse/lighthouse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import lighthouse from '@lighthouse-web3/sdk'
import { ethers } from 'ethers'
// for example
import { config as dotenvConfig } from 'dotenv'
import { resolve } from 'path'

dotenvConfig({ path: resolve(__dirname, '../../.env') })

const sign = async (privateKey: string) => {
const provider = new ethers.providers.JsonRpcProvider('https://eth.llamarpc.com');
const signer = new ethers.Wallet(privateKey, provider);
const messageRequested = (await lighthouse.getAuthMessage(await signer.getAddress())).data.message;
const signMessage = await signer.signMessage(messageRequested);
return signMessage
}

export const uploadModel = async (file: any, apiKey: string, privKey: string, shareAddr?: string[]) => {
return await lighthouse.upload(file, apiKey)
}

export const installEncryptModel = async (cid: string, privKey: string) => {
const provider = new ethers.providers.JsonRpcProvider('https://eth.llamarpc.com');
const signer = new ethers.Wallet(privKey, provider);
const pubKey = await signer.getAddress()
const signMessage = await sign(privKey)
console.log(cid)
lighthouse.fetchEncryptionKey(
cid,
pubKey,
signMessage
).then((key) => {
console.log(key)
}).catch((e) => {
console.log(e)
})
}

const example = async () => {
const apiKey = process.env.LIGHT_HOUSE_API as string
const privateKey = process.env.PRIVATE_KEY as string
const res = await uploadModel('./circuit.json', apiKey, privateKey)
console.log(res)

const model = await installEncryptModel(res.data.Hash, privateKey)
console.log(model)
}

Loading

0 comments on commit 194d8ba

Please sign in to comment.