README
@arcblock/did-agent-storage
Interface for define a storage class that can be used by [@arcblock/did-auth].
Table of Contents
Motivation & Spec
Fields
Possible fields to exist in a did-agent storage record
authorizeId: Primary keyownerDid: Owner DIDagentDid: Agent DIDappDid: Application DIDappPk: Application public keyappName: Application nameappDescription: Application descriptionappIcon: Application logo/iconcertificateContent: Application authorize content
APIs
Basic APIs that a did-agent storage should support:
create(authorizeId, payload): 创建记录update(authorizeId, updates): 更新记录read(authorizeId):按 authorizeId 查询delete(authorizeId):删除记录listByApp(appDid): 按应用查询listByOwner(ownerDid): 按所有者查询
Install
npm install @arcblock/did-agent-storage
// or
yarn add @arcblock/did-agent-storage
Usage
const StorageInterface = require('@arcblock/did-agent-storage');
let storage = {};
module.exports = class MemoryAgentStorage extends StorageInterface {
read(authorizeId) {
return storage[authorizeId];
}
create(authorizeId, payload = {}) {
storage[authorizeId] = Object.assign({ authorizeId }, payload);
return this.read(authorizeId);
}
update(authorizeId, updates) {
delete updates.authorizeId;
storage[authorizeId] = Object.assign(storage[authorizeId], updates);
return storage[authorizeId];
}
delete(authorizeId) {
delete storage[authorizeId];
}
listByOwner(ownerDid) {
Object.keys(storage)
.filter(x => storage[x].ownerDid === ownerDid)
.map(x => storage[x]);
}
listByApp(appDid) {
Object.keys(storage)
.filter(x => storage[x].appDid === appDid)
.map(x => storage[x]);
}
clear() {
storage = {};
}
};
Contributors
| Name | Website |
|---|---|
| wangshijun | https://ocap.arcblock.io |