Skip to content

Commit e62c827

Browse files
committed
Add Numbers Protocol IPFS service support
Related to #40 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/numbersprotocol/nit/issues/40?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent c7d43d3 commit e62c827

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/ipfs.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ let ProjectId = "";
1010
let ProjectSecret = "";
1111

1212
let EstuaryInstance;
13+
let NumbersProtocolInstance;
1314

1415
export async function initInfura(projectId, projectSecret) {
1516
ProjectId = projectId;
@@ -67,11 +68,11 @@ export async function w3sIpfsCat(cid) {
6768
}
6869

6970
export async function ipfsAddBytes(bytes) {
70-
return await infuraIpfsAddBytes(bytes);
71+
return await numbersProtocolIpfsAddBytes(bytes);
7172
}
7273

7374
export async function ipfsCat(cid) {
74-
return await w3sIpfsCat(cid);
75+
return await numbersProtocolIpfsCat(cid);
7576
}
7677

7778
export async function cidToJsonString(cid) {
@@ -107,4 +108,27 @@ export async function estuaryAdd(bytes) {
107108
} catch(error) {
108109
console.error(error);
109110
}
110-
}
111+
}
112+
113+
export async function initNumbersProtocol(apiKey) {
114+
NumbersProtocolInstance = new Estuary(apiKey);
115+
}
116+
117+
export async function numbersProtocolIpfsAddBytes(bytes) {
118+
let cid;
119+
try {
120+
cid = await NumbersProtocolInstance.addFromBuffer(bytes);
121+
return cid;
122+
} catch(error) {
123+
console.error(error);
124+
}
125+
}
126+
127+
export async function numbersProtocolIpfsCat(cid) {
128+
const url = `https://${cid}.ipfs.numbersprotocol.io`;
129+
const requestConfig = {
130+
timeout: { request: 30000 },
131+
}
132+
const r = await got.get(url, requestConfig);
133+
return r.rawBody;
134+
}

0 commit comments

Comments
 (0)