-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from hollow-leaf/feat/uploadFileCoin
feat: upload filecoin
- Loading branch information
Showing
6 changed files
with
396 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
LIGHT_HOUSE_API=lighthouseapi | ||
PRIVATE_KEY=priv_key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
Oops, something went wrong.