在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ipfs-shipyard/js-did-ipid开源软件地址:https://github.com/ipfs-shipyard/js-did-ipid开源编程语言:JavaScript 100.0%开源软件介绍:did-ipidThe IPID DID method implementation in JavaScript. Installation$ npm install did-ipid This library is written in modern JavaScript and is published in both CommonJS and ES module transpiled variants. If you target older browsers please make sure to transpile accordingly. Usageimport createIpid, { getDid } from 'did-ipid';
const did = await getDid(pem);
//=> Returns the DID associated to a private key in PEM format.
const ipid = await createIpid(ipfs);
const didDocument = await ipid.resolve('did:ipid:QmUTE4cxTxihntPEFqTprgbqyyS9YRaRcC8FXp6PACEjFG');
//=> Resolves a DID and returns the respective DID Document.
const didDocument = await ipid.create(pem, (document) => {
const publicKey = document.addPublicKey({
type: 'RsaVerificationKey2018',
publicKeyHex: '02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71',
});
const authentication = document.addAuthentication(publicKey.id);
const service = document.addService({
id: 'hub',
type: 'HubService',
serviceEndpoint: 'https://hub.example.com/',
});
});
//=> Creates a new DID and the corresponding DID Document based on the provided private key pem.
//=> The DID Document is published with the added publicKey, authentication and service.
const didDocument = await ipid.update(pem, (document) => {
document.removeService('hub');
document.addService({
id: 'messages',
type: 'MessagingService',
serviceEndpoint: 'https://example.com/messages/8377464',
});
});
//=> Updates a DID Document based on the DID associated to the provided private key pem.
//=> The DID Document is published without the `hub` service and with a new one called `messages`. APIgetDid(pem)Returns the DID associated to a private key in PEM format. pemType: A private key in PEM format. Supported formats: Example: -----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDCQZyRCPMcBPL2J2SuI2TduR7sy28wmcRzfj8fXQTbj1zJURku
...
-----END RSA PRIVATE KEY----- IPIDAn IPFS node is required to create an IPID instance. Please be sure to check js-ipfs, the JavaScript implementation of the IPFS protocol, to learn how to create one. There is currently only one option available during the creation of an IPID instance. The Example: import createIpid from 'did-ipid';
const ipid = await createIpid(ipfs, { lifetime: '24h' }); Notes:
resolve(did)Resolves a DID and provides the respective DID Document. Returns a Promise that resolves to the DID Document. didType: The DID to resolve. Example:
create(privateKeyPem, operations)Creates a new DID and respective DID Document by applying all the specified operations. Returns a Promise that resolves to the DID Document. privateKeyPemType: A private key in PEM format. Example: -----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDCQZyRCPMcBPL2J2SuI2TduR7sy28wmcRzfj8fXQTbj1zJURku
...
-----END RSA PRIVATE KEY----- operationsType: A function that receives a Document instance that provides methods to modify its content. update(privateKeyPem, operations)Updates an existing DID Document by applying all the specified operations. Returns a Promise that resolves to the DID Document. privateKeyPemType: A private key in PEM format. Example: -----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDCQZyRCPMcBPL2J2SuI2TduR7sy28wmcRzfj8fXQTbj1zJURku
...
-----END RSA PRIVATE KEY----- operationsType: A function that receives a Document instance that provides methods to modify its content. DocumentgetContent()Returns the current state of the documents content. addPublicKey(publicKey, [options])Adds a new Public Key to the document. Returns the added public key. publicKeyType: An object with all the Public Key required properties as defined in the DID Public Keys spec.
optionsType: Options to be used while adding a public key. idPrefixType: A prefix to be added to the public key id. revokePublicKey(id)Revokes a Public Key from the document. Also revokes an authentication that references this public key. idType: The id of the public key. addAuthentication(authentication)Adds a new Authentication to the document. Returns the added authentication. authenticationType: The id of the public key that is being referenced. removeAuthentication(id)Revokes an Authentication from the document. idType: The id authentication. addService(service, [options])Adds a new Service Endpoint to the document. Returns the added service. serviceType: An object with all the Service Endpoint required properties as defined in the DID Service Endpoints spec.
optionsType: Options to be used while adding a service. idPrefixType: A prefix to be added to the service id. removeService(id)Revokes a Service Endpoint from the document. idType: The id of the service endpoint. Tests$ npm test
$ npm test -- --watch # during development LicenseReleased under the MIT License. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论