-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (38 loc) · 1.75 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
34
35
36
37
38
39
40
41
42
43
44
45
46
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 * as Name from 'w3name'
import { filesFromPaths } from 'files-from-path'
import assert from 'node:assert'
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 source = core.getInput('source', { required: true })
assert(source.endsWith('.tar.gz'), 'source must point to a .tar.gz file')
const w3upPrivateKey = core.getInput('w3up-private-key', { required: true })
const w3upProof = core.getInput('w3up-proof', { required: true })
const w3namePrivateKey = core.getInput('w3name-private-key', { required: true })
const w3nameRevision = core.getInput('w3name-revision', { required: true })
const principal = ed25519.Signer.parse(w3upPrivateKey)
const web3Storage = await Client.create({ principal })
const proof = await parseProof(w3upProof)
const space = await web3Storage.addSpace(proof)
await web3Storage.setCurrentSpace(space.did())
const name = await Name.from(Buffer.from(w3namePrivateKey, 'hex'))
const revision = Name.Revision.decode(Buffer.from(w3nameRevision, 'hex'))
const cid = await web3Storage.uploadFile((await filesFromPaths([source]))[0])
console.log(`Uploaded as ${cid}`)
core.setOutput('cid', cid.toString())
const nextRevision = await Name.increment(revision, `/ipfs/${cid}`)
await Name.publish(nextRevision, name.key)
console.log('Updated name')
}
main().catch(err => core.setFailed(err.message))