Skip to content

Commit 8b741f7

Browse files
committed
Migrate to VC storage to IDX/Ceramic
Signed-off-by: Tiago Nascimento <[email protected]>
1 parent e1c3eda commit 8b741f7

File tree

3 files changed

+50
-35
lines changed

3 files changed

+50
-35
lines changed

app/assets/v2/js/ceramic.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/assets/v2/js/pages/profile-trust.js

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,13 +2248,23 @@ $(document).ready(function() {
22482248
});
22492249

22502250
const passportCredential = (() => {
2251-
2252-
const _3BOX_SPACE = 'gitcoin';
2253-
const _3BOX_FIELD = 'popp';
2251+
const CERAMIC_DOC_FAMILY = 'popp';
2252+
const CERAMIC_DOC_TAGS = [
2253+
'gitcoin',
2254+
'PoPP',
2255+
'ProofOfPersonhoodPassport',
2256+
'VerifiableCredential',
2257+
'DIDKit'
2258+
];
22542259

22552260
let credential;
22562261
let verifier;
22572262

2263+
const CERAMIC_DOC_OPTIONS = {
2264+
family: CERAMIC_DOC_FAMILY,
2265+
tags: CERAMIC_DOC_TAGS
2266+
};
2267+
22582268
const params = () => ({
22592269
'network': networkName,
22602270
'coinbase': selectedAccount
@@ -2291,26 +2301,26 @@ $(document).ready(function() {
22912301
<a ${style} href="${verifier}" target="_blank" class="btn btn-success">Verify</a>
22922302
<a ${style} href="${href}" class="btn btn-link" download="gitcoin-popp-vc.json"">Download</a>
22932303
</div>
2294-
<button ${style} type="button" class="btn btn-primary" id="vc-3box">Save to 3Box</button>
2304+
<button ${style} type="button" class="btn btn-primary" id="vc-ceramic">Save to Ceramic</button>
22952305
</div>
22962306
`;
22972307
};
22982308

22992309
const messages = {
2300-
auth: [
2301-
'Authenticate with 3Box',
2302-
'Authenticating with 3Box',
2303-
'Authenticated with 3Box'
2310+
init: [
2311+
'Initialize Ceramic client',
2312+
'Initializing Ceramic client',
2313+
'Initialized Ceramic client'
23042314
],
2305-
storage: [
2306-
`Open '${_3BOX_SPACE}' storage space on 3Box`,
2307-
`Opening '${_3BOX_SPACE}' storage space on 3Box`,
2308-
`Opened '${_3BOX_SPACE}' storage space on 3Box`
2315+
auth: [
2316+
'Authenticate with Ceramic client',
2317+
'Authenticating with Ceramic client',
2318+
'Authenticated with Ceramic client'
23092319
],
2310-
variable: [
2311-
`Save passport credential as '${_3BOX_FIELD}'`,
2312-
`Saving passport credential as '${_3BOX_FIELD}'`,
2313-
`Saved passport credential as '${_3BOX_FIELD}'`
2320+
write: [
2321+
'Save passport credential',
2322+
'Saving passport credential',
2323+
'Saved passport credential'
23142324
]
23152325
};
23162326

@@ -2323,26 +2333,29 @@ $(document).ready(function() {
23232333
return '<em>' + source[0] + '</em>';
23242334
};
23252335

2326-
const get3BoxContent = (auth, storage, variable) => {
2336+
const getContent = (init, auth, write) => {
23272337
let list = '<ul>';
23282338

23292339
list += '<li>';
2330-
list += getMessage(messages.auth, auth);
2340+
list += getMessage(messages.init, init);
23312341
list += '</li>';
23322342

23332343
list += '<li>';
2334-
list += getMessage(messages.storage, storage);
2344+
list += getMessage(messages.auth, auth);
23352345
list += '</li>';
23362346

23372347
list += '<li>';
2338-
list += getMessage(messages.variable, variable);
2348+
list += getMessage(messages.write, write);
23392349
list += '</li>';
23402350

23412351
list += '</ul>';
23422352

23432353
return `
23442354
<div>
2345-
<p><strong>3Box integration:</strong> you can save a POPP credential to 3Box.</p>
2355+
<p>
2356+
<strong>Ceramic integration:</strong>
2357+
you can save a POPP credential to Ceramic.
2358+
</p>
23462359
${list}
23472360
</div>
23482361
`;
@@ -2378,35 +2391,34 @@ $(document).ready(function() {
23782391
}
23792392
};
23802393

2381-
const vc3Box = async() => {
2394+
const vcCeramic = async() => {
23822395
const modal = $('.modal-body');
23832396
const base = baseContent();
23842397

2385-
modal.html(`${base} <hr /> ${get3BoxContent(false)}`);
2398+
modal.html(`${base} <hr /> ${getContent(false)}`);
2399+
2400+
const client = await Ceramic.initializeClient();
23862401

2387-
const storageBox = await Box.openBox(selectedAccount, provider);
23882402

2389-
modal.html(`${base} <hr /> ${get3BoxContent(true, false)}`);
2403+
modal.html(`${base} <hr /> ${getContent(true, false)}`);
23902404

2391-
const storageSpace = await storageBox.openSpace(_3BOX_SPACE);
2405+
await Ceramic.authenticateEthAddress(client, selectedAccount);
23922406

2393-
await storageSpace.syncDone;
23942407

2395-
modal.html(`${base} <hr /> ${get3BoxContent(true, true, false)}`);
2408+
modal.html(`${base} <hr /> ${getContent(true, true, false)}`);
23962409

2397-
const json = JSON.stringify(credential);
2410+
await Ceramic.writeDocument(client, credential, CERAMIC_DOC_OPTIONS);
23982411

2399-
await storageSpace.public.set(_3BOX_FIELD, json);
24002412

2401-
modal.html(`${base} <hr /> ${get3BoxContent(true, true, true)}`);
2413+
modal.html(`${base} <hr /> ${getContent(true, true, true)}`);
24022414

2403-
_alert('Your passport has been uploaded to 3Box', 'success', 5000);
2415+
_alert('Your passport has been uploaded to Ceramic', 'success', 5000);
24042416
};
24052417

2406-
return { vcPassport, vc3Box };
2418+
return { vcPassport, vcCeramic };
24072419
})();
24082420

24092421
$(document).on('click', '#vc-passport', passportCredential.vcPassport);
2410-
$(document).on('click', '#vc-3box', passportCredential.vc3Box);
2422+
$(document).on('click', '#vc-ceramic', passportCredential.vcCeramic);
24112423

24122424
});

app/dashboard/templates/profiles/profile.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@
130130
<script src="/dynamic/js/tokens_dynamic.js"></script>
131131
<script src="{% static "v2/js/tokens.js" %}"></script>
132132
<script src="{% static "v2/js/clipboard.js" %}"></script>
133-
{% endif %}
133+
<script type="module" src="{% static "v2/js/ceramic.min.js" %}"></script>
134+
{% endif %}
134135
<!-- jQuery -->
135136
<script src="{% static "v2/js/abi.js" %}"></script>
136137
<script>

0 commit comments

Comments
 (0)