Feat: use program.recoverFileSystem instead of doing it manually (#113)
This commit is contained in:
parent
0a1c57f393
commit
88725d3d36
|
|
@ -11,7 +11,7 @@
|
|||
"clipboard-copy": "^4.0.1",
|
||||
"qrcode-svg": "^1.1.0",
|
||||
"uint8arrays": "^4.0.2",
|
||||
"webnative": "^0.35.1"
|
||||
"webnative": "^0.36.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.29.2",
|
||||
|
|
@ -6322,9 +6322,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/webnative": {
|
||||
"version": "0.35.2",
|
||||
"resolved": "https://registry.npmjs.org/webnative/-/webnative-0.35.2.tgz",
|
||||
"integrity": "sha512-2TIK8Amt2M0STz3DFpxSgbujzhHjrwqaDgyTvIghzg6qGW9eHS73KwAC4ErjshFNlOPT7w6z1mVoIB9x3AUSJA==",
|
||||
"version": "0.36.0",
|
||||
"resolved": "https://registry.npmjs.org/webnative/-/webnative-0.36.0.tgz",
|
||||
"integrity": "sha512-gU+a3EvyqcG8yifZW+5ioQcuq/fRX4K3PXDqr2cSYnQhWc3C6DW5r/g+N5uFFL16huCJbn1lg0iSPJAu9El5Ww==",
|
||||
"dependencies": {
|
||||
"@ipld/dag-cbor": "^8.0.0",
|
||||
"@ipld/dag-pb": "^3.0.1",
|
||||
|
|
@ -10971,9 +10971,9 @@
|
|||
"requires": {}
|
||||
},
|
||||
"webnative": {
|
||||
"version": "0.35.2",
|
||||
"resolved": "https://registry.npmjs.org/webnative/-/webnative-0.35.2.tgz",
|
||||
"integrity": "sha512-2TIK8Amt2M0STz3DFpxSgbujzhHjrwqaDgyTvIghzg6qGW9eHS73KwAC4ErjshFNlOPT7w6z1mVoIB9x3AUSJA==",
|
||||
"version": "0.36.0",
|
||||
"resolved": "https://registry.npmjs.org/webnative/-/webnative-0.36.0.tgz",
|
||||
"integrity": "sha512-gU+a3EvyqcG8yifZW+5ioQcuq/fRX4K3PXDqr2cSYnQhWc3C6DW5r/g+N5uFFL16huCJbn1lg0iSPJAu9El5Ww==",
|
||||
"requires": {
|
||||
"@ipld/dag-cbor": "^8.0.0",
|
||||
"@ipld/dag-pb": "^3.0.1",
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
"clipboard-copy": "^4.0.1",
|
||||
"qrcode-svg": "^1.1.0",
|
||||
"uint8arrays": "^4.0.2",
|
||||
"webnative": "^0.35.1"
|
||||
"webnative": "^0.36.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.14"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
<script lang="ts">
|
||||
import * as RootKey from 'webnative/common/root-key'
|
||||
import * as UCAN from 'webnative/ucan/index'
|
||||
import * as DID from 'webnative/did/index'
|
||||
import * as uint8arrays from 'uint8arrays'
|
||||
|
||||
import { sessionStore } from '$src/stores'
|
||||
|
|
@ -60,40 +57,16 @@
|
|||
|
||||
storage.setItem(USERNAME_STORAGE_KEY, newUsername)
|
||||
|
||||
// Register the user with the `hashedNewUsername`
|
||||
const { success } = await authStrategy.register({
|
||||
username: hashedNewUsername
|
||||
// Recover user's file system
|
||||
const { success } = await $sessionStore.program.fileSystem.recover({
|
||||
newUsername: hashedNewUsername,
|
||||
oldUsername: hashedOldUsername,
|
||||
readKey
|
||||
})
|
||||
if (!success) {
|
||||
throw new Error('Failed to register new user')
|
||||
throw new Error('Failed to recover file system')
|
||||
}
|
||||
|
||||
// Build an ephemeral UCAN to authorize the dataRoot.update call
|
||||
const proof: string | null = await storage.getItem(
|
||||
storage.KEYS.ACCOUNT_UCAN
|
||||
)
|
||||
const ucan = await UCAN.build({
|
||||
dependencies: $sessionStore.program.components,
|
||||
potency: 'APPEND',
|
||||
resource: '*',
|
||||
proof: proof ? proof : undefined,
|
||||
lifetimeInSeconds: 60 * 3, // Three minutes
|
||||
audience: newRootDID,
|
||||
issuer: newRootDID
|
||||
})
|
||||
|
||||
const oldRootCID = await reference.dataRoot.lookup(hashedOldUsername)
|
||||
|
||||
// Update the dataRoot of the new user
|
||||
await reference.dataRoot.update(oldRootCID, ucan)
|
||||
|
||||
// Store the accountDID, which is used to namespace the readKey
|
||||
await RootKey.store({
|
||||
accountDID: newRootDID,
|
||||
readKey,
|
||||
crypto: crypto
|
||||
})
|
||||
|
||||
// Load account data into sessionStore
|
||||
await loadAccount(hashedNewUsername, newUsername)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue