Skip to content

Commit d181782

Browse files
authored
fix: fixes ceramic network connection (#66)
* fix: switch to internal getChainId
1 parent 7a261bf commit d181782

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

packages/snap/index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ <h1>Hello, Snaps!</h1>
3434
<textarea id="VC" rows="30" cols="50"></textarea>
3535
<br />
3636
<button class="saveVC">Save VC</button>
37+
<button class="saveVCC">Save VC Ceramic</button>
3738
<br />
3839
<hr />
3940
<input type="text" id="vcId" placeholder="VC ID" />
@@ -103,6 +104,8 @@ <h1>Hello, Snaps!</h1>
103104
const getVCBtn = document.querySelector('button.getVCs');
104105

105106
const saveBtn = document.querySelector('button.saveVC');
107+
const saveCeramicBtn = document.querySelector('button.saveVCC');
108+
106109

107110
const getVPBtn = document.querySelector('button.getVP');
108111

@@ -132,6 +135,7 @@ <h1>Hello, Snaps!</h1>
132135
getVCBtn.addEventListener('click', getVCs);
133136

134137
saveBtn.addEventListener('click', saveVC);
138+
saveCeramicBtn.addEventListener('click', saveVCC);
135139

136140
getVPBtn.addEventListener('click', getVp);
137141

@@ -293,6 +297,26 @@ <h1>Hello, Snaps!</h1>
293297
alert('Problem happened: ' + err.message || err);
294298
}
295299
}
300+
301+
async function saveVCC() {
302+
try {
303+
const vc = JSON.parse(document.getElementById('VC').value);
304+
console.log("saving ceramic")
305+
const response = await ethereum.request({
306+
method: `wallet_snap_${snapId}`,
307+
params: {
308+
method: 'saveVC',
309+
params: {
310+
verifiableCredential: vc,
311+
options: { store: ['ceramic'] }
312+
},
313+
}
314+
});
315+
} catch (err) {
316+
console.error(err);
317+
alert('Problem happened: ' + err.message || err);
318+
}
319+
}
296320
async function getVCs() {
297321
console.log("doing this..")
298322
try {

packages/snap/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/blockchain-lab-um/ssi-snap.git"
88
},
99
"source": {
10-
"shasum": "vkMs8lhcSBVdKzDFju/j7gK9UmYlalZIlHk5jbqY9pk=",
10+
"shasum": "tgyPYa4WXy5Hh5dTD3PEKkIXr3d/7d/s6vsUpvlZk1g=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/snap.js",

packages/snap/src/utils/ceramicUtils.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { CeramicClient } from '@ceramicnetwork/http-client';
22
import { DIDSession } from 'did-session';
3-
import { getCurrentAccount } from './snapUtils';
3+
import { getCurrentAccount, getCurrentNetwork } from './snapUtils';
44
import { DID } from 'dids';
55
import { SnapsGlobalObject } from '@metamask/snaps-types';
6-
import { EthereumWebAuth, getAccountId } from '@didtools/pkh-ethereum';
6+
import { EthereumWebAuth } from '@didtools/pkh-ethereum';
7+
import { AccountId } from 'caip';
78

89
const ceramicDID = { did: undefined } as { did: DID | undefined };
910

@@ -25,14 +26,21 @@ export async function authenticateWithEthereum(
2526
if (ceramicDID.did) return ceramicDID.did;
2627
const account = await getCurrentAccount(snap);
2728
if (!account) throw Error('User denied error');
28-
const accountId = await getAccountId(snap, account);
29+
const ethChainId = await getCurrentNetwork(snap);
30+
const chainId = `eip155:${ethChainId}`;
31+
32+
const accountId = new AccountId({
33+
address: account,
34+
chainId,
35+
});
2936

30-
const authMethod = await EthereumWebAuth.getAuthMethod(ethereum, accountId);
3137
typeof window;
3238

3339
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
3440
window.location = {} as any;
3541
window.location.hostname = 'ssi-snap';
42+
43+
const authMethod = await EthereumWebAuth.getAuthMethod(ethereum, accountId);
3644
const session = await DIDSession.authorize(authMethod, {
3745
resources: [`ceramic://*`],
3846
});

0 commit comments

Comments
 (0)