@dwn-protocol/id-sdk 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -3
- package/src/agent/app-data-store.ts +0 -365
- package/src/agent/did-manager.ts +0 -393
- package/src/agent/dwn-manager.ts +0 -548
- package/src/agent/identity-manager.ts +0 -165
- package/src/agent/index.ts +0 -19
- package/src/agent/json-rpc.ts +0 -107
- package/src/agent/key-manager.ts +0 -302
- package/src/agent/kms-local.ts +0 -412
- package/src/agent/outbox.ts +0 -128
- package/src/agent/rpc-client.ts +0 -223
- package/src/agent/store-managed-did.ts +0 -295
- package/src/agent/store-managed-identity.ts +0 -243
- package/src/agent/store-managed-key.ts +0 -754
- package/src/agent/sync-manager.ts +0 -631
- package/src/agent/test-managed-agent.ts +0 -299
- package/src/agent/types/agent.ts +0 -145
- package/src/agent/types/managed-key.ts +0 -442
- package/src/agent/utils.ts +0 -190
- package/src/common/convert.ts +0 -424
- package/src/common/index.ts +0 -9
- package/src/common/multicodec.ts +0 -176
- package/src/common/object.ts +0 -43
- package/src/common/stores.ts +0 -125
- package/src/common/stream-node.ts +0 -381
- package/src/common/stream.ts +0 -406
- package/src/common/type-utils.ts +0 -117
- package/src/common/types.ts +0 -48
- package/src/credentials/credential-bbs.ts +0 -419
- package/src/credentials/credential.ts +0 -324
- package/src/credentials/index.ts +0 -5
- package/src/credentials/presentation.ts +0 -182
- package/src/credentials/status-list.ts +0 -365
- package/src/credentials/utils.ts +0 -58
- package/src/credentials/validators.ts +0 -52
- package/src/crypto/algorithms-api/aes/base.ts +0 -49
- package/src/crypto/algorithms-api/aes/ctr.ts +0 -51
- package/src/crypto/algorithms-api/aes/index.ts +0 -2
- package/src/crypto/algorithms-api/crypto-algorithm.ts +0 -127
- package/src/crypto/algorithms-api/crypto-key.ts +0 -56
- package/src/crypto/algorithms-api/ec/base.ts +0 -39
- package/src/crypto/algorithms-api/ec/ecdh.ts +0 -53
- package/src/crypto/algorithms-api/ec/ecdsa.ts +0 -37
- package/src/crypto/algorithms-api/ec/eddsa.ts +0 -30
- package/src/crypto/algorithms-api/ec/index.ts +0 -4
- package/src/crypto/algorithms-api/errors.ts +0 -29
- package/src/crypto/algorithms-api/index.ts +0 -6
- package/src/crypto/algorithms-api/pbkdf/index.ts +0 -1
- package/src/crypto/algorithms-api/pbkdf/pbkdf2.ts +0 -91
- package/src/crypto/crypto-algorithms/aes-ctr.ts +0 -70
- package/src/crypto/crypto-algorithms/bbs.ts +0 -110
- package/src/crypto/crypto-algorithms/ecdh.ts +0 -115
- package/src/crypto/crypto-algorithms/ecdsa.ts +0 -111
- package/src/crypto/crypto-algorithms/eddsa.ts +0 -110
- package/src/crypto/crypto-algorithms/index.ts +0 -6
- package/src/crypto/crypto-algorithms/pbkdf2.ts +0 -54
- package/src/crypto/crypto-primitives/aes-ctr.ts +0 -131
- package/src/crypto/crypto-primitives/aes-gcm.ts +0 -138
- package/src/crypto/crypto-primitives/bbs.ts +0 -183
- package/src/crypto/crypto-primitives/concat-kdf.ts +0 -207
- package/src/crypto/crypto-primitives/ed25519.ts +0 -201
- package/src/crypto/crypto-primitives/index.ts +0 -10
- package/src/crypto/crypto-primitives/pbkdf2.ts +0 -78
- package/src/crypto/crypto-primitives/secp256k1.ts +0 -322
- package/src/crypto/crypto-primitives/x25519.ts +0 -101
- package/src/crypto/crypto-primitives/xchacha20-poly1305.ts +0 -46
- package/src/crypto/crypto-primitives/xchacha20.ts +0 -34
- package/src/crypto/index.ts +0 -8
- package/src/crypto/jose.ts +0 -948
- package/src/crypto/types/crypto-key.ts +0 -4
- package/src/crypto/types/iddwn-crypto.ts +0 -119
- package/src/crypto/utils.ts +0 -200
- package/src/did-api.ts +0 -72
- package/src/dids/dht.ts +0 -412
- package/src/dids/did-dht.ts +0 -436
- package/src/dids/did-ion.ts +0 -613
- package/src/dids/did-key.ts +0 -791
- package/src/dids/did-resolver.ts +0 -107
- package/src/dids/index.ts +0 -9
- package/src/dids/resolver-cache-level.ts +0 -82
- package/src/dids/resolver-cache-noop.ts +0 -25
- package/src/dids/types.ts +0 -278
- package/src/dids/utils.ts +0 -129
- package/src/dwn-api.ts +0 -584
- package/src/iddwn.ts +0 -241
- package/src/identity-agent/index.ts +0 -270
- package/src/index.ts +0 -26
- package/src/interfaces/metadata.ts +0 -163
- package/src/interfaces/queue.ts +0 -108
- package/src/interfaces/services.ts +0 -122
- package/src/interfaces/transactions.ts +0 -220
- package/src/protocol.ts +0 -68
- package/src/proxy-agent/index.ts +0 -255
- package/src/record.ts +0 -521
- package/src/service-options.ts +0 -62
- package/src/typings/decentralized-identity__ion-pow-sdk.d.ts +0 -7
- package/src/user-agent/index.ts +0 -295
- package/src/utils.ts +0 -29
- package/src/vc-api.ts +0 -505
package/src/interfaces/queue.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type { IDAgent } from '../agent/index.js';
|
|
2
|
-
|
|
3
|
-
import { createLibp2p } from 'libp2p';
|
|
4
|
-
import { circuitRelayTransport } from 'libp2p/circuit-relay';
|
|
5
|
-
import { gossipsub } from '@chainsafe/libp2p-gossipsub';
|
|
6
|
-
import { identifyService } from 'libp2p/identify';
|
|
7
|
-
|
|
8
|
-
import { kadDHT } from '@libp2p/kad-dht';
|
|
9
|
-
import { mplex } from '@libp2p/mplex';
|
|
10
|
-
import { noise } from '@chainsafe/libp2p-noise';
|
|
11
|
-
import { PubSub } from 'pubsub-js';
|
|
12
|
-
import { webRTCStar } from '@libp2p/webrtc-star';
|
|
13
|
-
import { yamux } from '@chainsafe/libp2p-yamux';
|
|
14
|
-
|
|
15
|
-
export class Queue {
|
|
16
|
-
private agent: IDAgent;
|
|
17
|
-
private connectedDid: string;
|
|
18
|
-
private _star: any;
|
|
19
|
-
|
|
20
|
-
constructor(options: { agent: IDAgent, connectedDid: string }) {
|
|
21
|
-
this.agent = options.agent;
|
|
22
|
-
this.connectedDid = options.connectedDid;
|
|
23
|
-
|
|
24
|
-
this._star = webRTCStar();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async createPeer(): Promise<any> {
|
|
28
|
-
|
|
29
|
-
return await createLibp2p({
|
|
30
|
-
addresses: {
|
|
31
|
-
listen: [
|
|
32
|
-
// '/dns4/star.abaxx.id/tcp/443/wss/p2p-webrtc-star/',
|
|
33
|
-
'/dns4/star.comtrol.io/tcp/443/wss/p2p-webrtc-star/',
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
transports: [
|
|
37
|
-
this._star.transport,
|
|
38
|
-
circuitRelayTransport({
|
|
39
|
-
discoverRelays: 1,
|
|
40
|
-
}),
|
|
41
|
-
],
|
|
42
|
-
connectionEncryption: [
|
|
43
|
-
//@ts-ignore
|
|
44
|
-
noise(), // elliptic curve Diffie-Hellman key exchange using Curve e25519
|
|
45
|
-
],
|
|
46
|
-
streamMuxers: [
|
|
47
|
-
//@ts-ignore
|
|
48
|
-
yamux(), mplex(),
|
|
49
|
-
],
|
|
50
|
-
peerDiscovery: [
|
|
51
|
-
this._star.discovery,
|
|
52
|
-
],
|
|
53
|
-
services: {
|
|
54
|
-
//@ts-ignore
|
|
55
|
-
pubsub: gossipsub({
|
|
56
|
-
allowPublishToZeroPeers : true,
|
|
57
|
-
enabled : true,
|
|
58
|
-
emitSelf : true,
|
|
59
|
-
}),
|
|
60
|
-
identify : identifyService(),
|
|
61
|
-
dht : kadDHT({
|
|
62
|
-
clientMode: true,
|
|
63
|
-
}),
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async send(node, topic, message) {
|
|
70
|
-
node?.services?.pubsub?.publish(topic, new TextEncoder().encode(message)).catch((err) => {
|
|
71
|
-
return { ok: false, error: err.message, timestsamp: new Date().getTime() };
|
|
72
|
-
});
|
|
73
|
-
return { ok: true, timestsamp: new Date().getTime() };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async publish(topic, message, relayers = []) {
|
|
77
|
-
const response = await fetch(`${relayers[0]}/publish`, {
|
|
78
|
-
method : 'POST',
|
|
79
|
-
mode : 'cors',
|
|
80
|
-
cache : 'no-cache',
|
|
81
|
-
headers : {
|
|
82
|
-
'Accept' : '*/*',
|
|
83
|
-
'Content-Type' : 'application/json',
|
|
84
|
-
},
|
|
85
|
-
body: JSON.stringify({
|
|
86
|
-
topic,
|
|
87
|
-
message,
|
|
88
|
-
}),
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
PubSub.publish(topic, message);
|
|
92
|
-
return await response.text();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async subscribe(topic, cb) {
|
|
96
|
-
const relaySubscriber = (msg, data) => {
|
|
97
|
-
if (msg === topic) {
|
|
98
|
-
cb(data);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
const subscriber = PubSub.subscribe(topic, relaySubscriber);
|
|
102
|
-
return subscriber;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async unsubscribe(topic) {
|
|
106
|
-
PubSub.unsubscribe(topic);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import type { IDAgent } from '../agent/index.js';
|
|
2
|
-
|
|
3
|
-
export class Services {
|
|
4
|
-
private agent: IDAgent;
|
|
5
|
-
private connectedDid: string;
|
|
6
|
-
|
|
7
|
-
constructor(options: { agent: IDAgent, connectedDid: string }) {
|
|
8
|
-
this.agent = options.agent;
|
|
9
|
-
this.connectedDid = options.connectedDid;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async get(payload) {
|
|
13
|
-
try {
|
|
14
|
-
const headers = new Headers();
|
|
15
|
-
for (let header of payload.headers) {
|
|
16
|
-
headers.append(header.name, header.value);
|
|
17
|
-
}
|
|
18
|
-
const response = await fetch(payload.uri, {
|
|
19
|
-
method : 'GET',
|
|
20
|
-
mode : 'cors',
|
|
21
|
-
cache : 'no-cache',
|
|
22
|
-
headers : headers,
|
|
23
|
-
});
|
|
24
|
-
if (!response.ok) {
|
|
25
|
-
return { status: response.status };
|
|
26
|
-
}
|
|
27
|
-
const json = await response.json();
|
|
28
|
-
return json;
|
|
29
|
-
|
|
30
|
-
} catch (e) {
|
|
31
|
-
return { status: 400, error: e };
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async post(payload) {
|
|
36
|
-
try {
|
|
37
|
-
|
|
38
|
-
const headers = new Headers();
|
|
39
|
-
for (let header of payload.headers) {
|
|
40
|
-
headers.append(header.name, header.value);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const response = await fetch(payload.uri, {
|
|
44
|
-
method : 'POST',
|
|
45
|
-
mode : 'cors',
|
|
46
|
-
cache : 'no-cache',
|
|
47
|
-
headers : headers,
|
|
48
|
-
body : JSON.stringify(payload.body),
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
if (!response.ok) {
|
|
52
|
-
return { status: response.status };
|
|
53
|
-
}
|
|
54
|
-
const json = await response.json();
|
|
55
|
-
return json;
|
|
56
|
-
|
|
57
|
-
} catch (e) {
|
|
58
|
-
return { status: 400, error: e };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async put(payload) {
|
|
64
|
-
try {
|
|
65
|
-
|
|
66
|
-
const headers = new Headers();
|
|
67
|
-
for (let header of payload.headers) {
|
|
68
|
-
headers.append(header.name, header.value);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const response = await fetch(payload.uri, {
|
|
72
|
-
method : 'PUT',
|
|
73
|
-
mode : 'cors',
|
|
74
|
-
cache : 'no-cache',
|
|
75
|
-
headers : headers,
|
|
76
|
-
body : JSON.stringify(payload.body),
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
if (!response.ok) {
|
|
80
|
-
return { status: response.status };
|
|
81
|
-
}
|
|
82
|
-
const json = await response.json();
|
|
83
|
-
return json;
|
|
84
|
-
|
|
85
|
-
} catch (e) {
|
|
86
|
-
return { status: 400 };
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async proxy(payload) {
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
const headers = new Headers();
|
|
95
|
-
for (let header of payload.headers) {
|
|
96
|
-
headers.append(header.name, header.value);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const proxyRequest: any = {
|
|
100
|
-
method : payload.method,
|
|
101
|
-
mode : 'cors',
|
|
102
|
-
cache : 'no-cache',
|
|
103
|
-
headers : headers,
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
payload?.body ? proxyRequest.body = JSON.stringify(payload) : undefined;
|
|
107
|
-
|
|
108
|
-
const response = await fetch(payload.proxy, proxyRequest);
|
|
109
|
-
|
|
110
|
-
if (!response.ok) {
|
|
111
|
-
return { status: response.status, payload };
|
|
112
|
-
}
|
|
113
|
-
const json = await response.json();
|
|
114
|
-
return json;
|
|
115
|
-
|
|
116
|
-
} catch (e) {
|
|
117
|
-
return { status: 400, error: e };
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
}
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import type { IDAgent } from '../agent/index.js';
|
|
2
|
-
|
|
3
|
-
import { CID } from 'multiformats';
|
|
4
|
-
import { ethers } from 'ethers';
|
|
5
|
-
|
|
6
|
-
import bs58 from 'bs58';
|
|
7
|
-
|
|
8
|
-
import { getServiceDwnEndpoints } from '../service-options.js';
|
|
9
|
-
import _ from 'lodash';
|
|
10
|
-
|
|
11
|
-
export class Transactions {
|
|
12
|
-
private agent: IDAgent;
|
|
13
|
-
private connectedDid: string;
|
|
14
|
-
private _provider: any;
|
|
15
|
-
private _signer: any;
|
|
16
|
-
|
|
17
|
-
constructor(options: { agent: IDAgent, connectedDid: string }) {
|
|
18
|
-
this.agent = options.agent;
|
|
19
|
-
this.connectedDid = options.connectedDid;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async config() {
|
|
23
|
-
const h =
|
|
24
|
-
'1220' +'0x32216e417b6f98f95febedf6a747c5020ea95558fbebd98ba98a155791b0b6d2'.slice(2);
|
|
25
|
-
const b = Buffer.from(h, 'hex');
|
|
26
|
-
const c = bs58.encode(b);
|
|
27
|
-
const r = await fetch(`https://dwn.infura-ipfs.io/ipfs/${CID.parse(c).toV1().toString()}`);
|
|
28
|
-
return JSON.parse(bs58.decode(await r.text()).toString());
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async getJWT(id) {
|
|
32
|
-
const relayer = _.sample(await getServiceDwnEndpoints());
|
|
33
|
-
const response = await fetch(`${relayer}/login?id=${id}`, {
|
|
34
|
-
method : 'POST',
|
|
35
|
-
mode : 'cors',
|
|
36
|
-
cache : 'no-cache',
|
|
37
|
-
headers : {
|
|
38
|
-
Accept : '*/*',
|
|
39
|
-
'Content-Type' : 'application/json',
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return await response.text();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/*********************************************************************************************************************
|
|
47
|
-
* Ethereum Transactions
|
|
48
|
-
*********************************************************************************************************************/
|
|
49
|
-
|
|
50
|
-
async connectToMetamask() {
|
|
51
|
-
//@ts-ignore
|
|
52
|
-
this._provider = new ethers.BrowserProvider(window.ethereum);
|
|
53
|
-
this._signer = await this._provider.getSigner();
|
|
54
|
-
//@ts-ignore
|
|
55
|
-
window.ethereum.request({
|
|
56
|
-
method : 'wallet_addEthereumChain',
|
|
57
|
-
params : [{
|
|
58
|
-
chainId : '0x5',
|
|
59
|
-
rpcUrls : ['https://rpc-goerli.flashbots.net'],
|
|
60
|
-
chainName : 'Goerli Flashbots Protect',
|
|
61
|
-
nativeCurrency : {
|
|
62
|
-
name : 'ETH',
|
|
63
|
-
symbol : 'ETH',
|
|
64
|
-
decimals : 18,
|
|
65
|
-
},
|
|
66
|
-
blockExplorerUrls: ['https://goerli.etherscan.io/'],
|
|
67
|
-
}],
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async sendEth(to, value) {
|
|
72
|
-
const tx = await this._signer.sendTransaction({
|
|
73
|
-
to : to,
|
|
74
|
-
value : ethers.parseEther(value),
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const receipt = await tx.wait();
|
|
78
|
-
return receipt;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/*********************************************************************************************************************
|
|
82
|
-
* Chia Transactions
|
|
83
|
-
*********************************************************************************************************************/
|
|
84
|
-
|
|
85
|
-
async sendChia(wallet_id, amount, address, token) {
|
|
86
|
-
const relayer = _.sample(await getServiceDwnEndpoints());
|
|
87
|
-
const response = await fetch(`${relayer}/send-chia`, {
|
|
88
|
-
method : 'POST',
|
|
89
|
-
mode : 'cors',
|
|
90
|
-
cache : 'no-cache',
|
|
91
|
-
headers : {
|
|
92
|
-
Accept : '*/*',
|
|
93
|
-
'Content-Type' : 'application/json',
|
|
94
|
-
Authorization : `Bearer ${token}`,
|
|
95
|
-
},
|
|
96
|
-
body: JSON.stringify({
|
|
97
|
-
wallet_id : wallet_id,
|
|
98
|
-
amount : amount,
|
|
99
|
-
address : address,
|
|
100
|
-
}),
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
return await response.text();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async getChiaBalance(wallet_id, token) {
|
|
107
|
-
const relayer = _.sample(await getServiceDwnEndpoints());
|
|
108
|
-
const response = await fetch(
|
|
109
|
-
`${relayer}/get-chia-balance?wallet_id=${wallet_id}`,
|
|
110
|
-
{
|
|
111
|
-
method : 'GET',
|
|
112
|
-
mode : 'cors',
|
|
113
|
-
cache : 'no-cache',
|
|
114
|
-
headers : {
|
|
115
|
-
Accept : '*/*',
|
|
116
|
-
'Content-Type' : 'application/json',
|
|
117
|
-
Authorization : `Bearer ${token}`,
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
return await response.text();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async addToChiaDataLayer(key, value, token) {
|
|
126
|
-
const relayer = _.sample(await getServiceDwnEndpoints());
|
|
127
|
-
const response = await fetch(`${relayer}/add-to-data-layer`, {
|
|
128
|
-
method : 'POST',
|
|
129
|
-
mode : 'cors',
|
|
130
|
-
cache : 'no-cache',
|
|
131
|
-
headers : {
|
|
132
|
-
Accept : '*/*',
|
|
133
|
-
'Content-Type' : 'application/json',
|
|
134
|
-
Authorization : `Bearer ${token}`,
|
|
135
|
-
},
|
|
136
|
-
body: JSON.stringify({
|
|
137
|
-
key : key,
|
|
138
|
-
value : value,
|
|
139
|
-
}),
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
return await response.text();
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async bulkAddToChiaDataLayer(keys, values, token) {
|
|
146
|
-
const relayer = _.sample(await getServiceDwnEndpoints());
|
|
147
|
-
const response = await fetch(`${relayer}/bulk-add-to-data-layer`, {
|
|
148
|
-
method : 'POST',
|
|
149
|
-
mode : 'cors',
|
|
150
|
-
cache : 'no-cache',
|
|
151
|
-
headers : {
|
|
152
|
-
Accept : '*/*',
|
|
153
|
-
'Content-Type' : 'application/json',
|
|
154
|
-
Authorization : `Bearer ${token}`,
|
|
155
|
-
},
|
|
156
|
-
body: JSON.stringify({
|
|
157
|
-
keys : keys,
|
|
158
|
-
values : values,
|
|
159
|
-
}),
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
return await response.text();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
async getValuesFromChiaDataLayer(id, token) {
|
|
166
|
-
const relayer = _.sample(await getServiceDwnEndpoints());
|
|
167
|
-
const response = await fetch(
|
|
168
|
-
`${relayer}/get-values-from-data-layer?id=${id}`,
|
|
169
|
-
{
|
|
170
|
-
method : 'GET',
|
|
171
|
-
mode : 'cors',
|
|
172
|
-
cache : 'no-cache',
|
|
173
|
-
headers : {
|
|
174
|
-
Accept : '*/*',
|
|
175
|
-
'Content-Type' : 'application/json',
|
|
176
|
-
Authorization : `Bearer ${token}`,
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
return await response.text();
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
async mintChiaNFT(uris, hash, token) {
|
|
185
|
-
const relayer = _.sample(await getServiceDwnEndpoints());
|
|
186
|
-
const response = await fetch(`${relayer}/mint-nft`, {
|
|
187
|
-
method : 'POST',
|
|
188
|
-
mode : 'cors',
|
|
189
|
-
cache : 'no-cache',
|
|
190
|
-
headers : {
|
|
191
|
-
Accept : '*/*',
|
|
192
|
-
'Content-Type' : 'application/json',
|
|
193
|
-
Authorization : `Bearer ${token}`,
|
|
194
|
-
},
|
|
195
|
-
body: JSON.stringify({
|
|
196
|
-
uris : uris,
|
|
197
|
-
hash : hash,
|
|
198
|
-
}),
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
return await response.text();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
async getChiaNFTs(wallet_id, token) {
|
|
205
|
-
const relayer = _.sample(await getServiceDwnEndpoints());
|
|
206
|
-
const response = await fetch(`${relayer}/get-nfts?wallet_id=${wallet_id}`, {
|
|
207
|
-
method : 'GET',
|
|
208
|
-
mode : 'cors',
|
|
209
|
-
cache : 'no-cache',
|
|
210
|
-
headers : {
|
|
211
|
-
Accept : '*/*',
|
|
212
|
-
'Content-Type' : 'application/json',
|
|
213
|
-
Authorization : `Bearer ${token}`,
|
|
214
|
-
},
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
return await response.text();
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
}
|
package/src/protocol.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { IDAgent } from './agent/index.js';
|
|
2
|
-
import type { ProtocolsConfigure } from '@dwn-protocol/id';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The protocol configure message carries the protocol definition and is used
|
|
6
|
-
* to setup the protocol.
|
|
7
|
-
*
|
|
8
|
-
* @beta
|
|
9
|
-
*/
|
|
10
|
-
export type ProtocolsConfigureMessage = ProtocolsConfigure['message'];
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Metadata of the protocol
|
|
14
|
-
*
|
|
15
|
-
* @beta
|
|
16
|
-
*/
|
|
17
|
-
type ProtocolMetadata = {
|
|
18
|
-
author: string;
|
|
19
|
-
messageCid?: string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The Protocol API abstraction class. It's used to represent and retrieve a protocol and
|
|
24
|
-
* also to install (send) protocols to other DIDs.
|
|
25
|
-
*
|
|
26
|
-
* @beta
|
|
27
|
-
*/
|
|
28
|
-
export class Protocol {
|
|
29
|
-
private _agent: IDAgent;
|
|
30
|
-
private _metadata: ProtocolMetadata;
|
|
31
|
-
private _protocolsConfigureMessage: ProtocolsConfigureMessage;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The protocol definition: types, structure and publish status
|
|
35
|
-
*/
|
|
36
|
-
get definition() {
|
|
37
|
-
return this._protocolsConfigureMessage.descriptor.definition;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
constructor(agent: IDAgent, protocolsConfigureMessage: ProtocolsConfigureMessage, metadata: ProtocolMetadata) {
|
|
41
|
-
this._agent = agent;
|
|
42
|
-
this._metadata = metadata;
|
|
43
|
-
this._protocolsConfigureMessage = protocolsConfigureMessage;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Returns the protocol as a JSON object.
|
|
48
|
-
*/
|
|
49
|
-
toJSON() {
|
|
50
|
-
return this._protocolsConfigureMessage;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Sends the protocol to a remote DWN by specifying their DID
|
|
55
|
-
* @param target - the DID to send the protocol to
|
|
56
|
-
* @returns the status of the send protocols request
|
|
57
|
-
*/
|
|
58
|
-
async send(target: string) {
|
|
59
|
-
const { reply } = await this._agent.sendDwnRequest({
|
|
60
|
-
author : this._metadata.author,
|
|
61
|
-
messageCid : this._metadata.messageCid,
|
|
62
|
-
messageType : 'ProtocolsConfigure',
|
|
63
|
-
target : target,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return { status: reply.status };
|
|
67
|
-
}
|
|
68
|
-
}
|