-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (28 loc) · 1.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import core from '@actions/core'
import { ed25519 } from '@ucanto/principal'
import * as Client from '@web3-storage/w3up-client'
import { CarReader } from '@ipld/car'
import { importDAG } from '@ucanto/core/delegation'
import { filesFromPaths } from 'files-from-path'
const parseProof = async data => {
const blocks = []
const reader = await CarReader.fromBytes(Buffer.from(data, 'base64'))
for await (const block of reader.blocks()) {
blocks.push(block)
}
return importDAG(blocks)
}
const main = async () => {
const path = core.getInput('path', { required: true })
const privateKey = core.getInput('private-key', { required: true })
const proofEncoded = core.getInput('proof', { required: true })
const principal = ed25519.Signer.parse(privateKey)
const web3Storage = await Client.create({ principal })
const proof = await parseProof(proofEncoded)
const space = await web3Storage.addSpace(proof)
await web3Storage.setCurrentSpace(space.did())
const cid = await web3Storage.uploadFile((await filesFromPaths([path]))[0])
console.log(`Uploaded as ${cid}`)
core.setOutput('cid', cid.toString())
}
main().catch(err => core.setFailed(err.message))