|
import { Web5PlatformAgent } from '@web5/agent'; |
|
import { Web5 } from '@web5/api'; |
|
import { appendFile } from 'fs/promises'; |
|
|
|
const password = '<some-password>' |
|
const { web5, did, recoveryPhrase } = await Web5.connect({ |
|
password, |
|
sync : '0s', |
|
techPreview : { dwnEndpoints: ['http://localhost:3000'] } |
|
}); |
|
console.log('connected did ', did); |
|
console.log('recoveryPhrase ', recoveryPhrase); |
|
|
|
const agent = web5.agent as Web5PlatformAgent; |
|
console.log('agent did ', agent.agentDid.uri); |
|
for (let i = 0; i < 2; i++) { |
|
const identity = await agent.identity.create({ |
|
didMethod : 'dht', |
|
metadata : { name: 'Default' }, |
|
didOptions : { |
|
services: [ |
|
{ |
|
id : 'dwn', |
|
type : 'DecentralizedWebNode', |
|
serviceEndpoint : ['http://localhost:3000'], |
|
enc : '#enc', |
|
sig : '#sig', |
|
} |
|
], |
|
verificationMethods: [ |
|
{ |
|
algorithm : 'Ed25519', |
|
id : 'sig', |
|
purposes : ['assertionMethod', 'authentication'] |
|
}, |
|
{ |
|
algorithm : 'secp256k1', |
|
id : 'enc', |
|
purposes : ['keyAgreement'] |
|
} |
|
] |
|
} |
|
}); |
|
await agent.identity.manage({ portableIdentity: await identity.export() }); |
|
await agent.sync.registerIdentity({ did: identity.did.uri }); |
|
} |
|
|
|
const identities = await agent.identity.list(); |
|
identities.map((identity) => { |
|
console.log('identity.did.metadata', identity.did); |
|
identity.export().then((portableIdentity) => { |
|
console.log('portableIdentity', portableIdentity); |
|
appendFile('identities.json', JSON.stringify(portableIdentity, null, 2) + '\n').then(() => console.log('identity exported')); |
|
}); |
|
}); |