Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 69 additions & 57 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*!
* Copyright (c) 2020-2024 Digital Bazaar, Inc. All rights reserved.
*/
import * as base58 from 'base58-universal';
import * as base64url from 'base64url-universal';
// import * as base58 from 'base58-universal';
// import * as base64url from 'base64url-universal';
Comment on lines +4 to +5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove all the commented stuff here and below so it's easier to understand what would be approved and get merged?

Copy link
Member

@dlongley dlongley Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, just saw the "disclaimer" above.

EDIT: Though, I still think it would be better to remove before approval so it's easier to review and to understand what will get merged.

import {renderToNfc, supportsNFC} from './nfcRenderer.js';
import {config} from '@bedrock/web';
import {
Ed25519VerificationKey2020
Expand All @@ -19,10 +20,10 @@ const supportedSignerTypes = new Map([
]
]);

const multibaseDecoders = new Map([
['u', base64url],
['z', base58],
]);
// const multibaseDecoders = new Map([
// ['u', base64url],
// ['z', base58],
// ]);

export async function createCapabilities({profileId, request}) {
// TODO: validate `request`
Expand Down Expand Up @@ -178,62 +179,73 @@ export async function openFirstPartyWindow(event) {
export const prettify = obj => JSON.stringify(obj, null, 2);

export async function toNFCPayload({credential}) {
const nfcRenderingTemplate2024 = _getNFCRenderingTemplate2024({credential});
const bytes = await _decodeMultibase(nfcRenderingTemplate2024.payload);
return {bytes};
}

export function hasNFCPayload({credential}) {
try {
const nfcRenderingTemplate2024 = _getNFCRenderingTemplate2024({credential});
if(!nfcRenderingTemplate2024) {
return false;
}

return true;
} catch(e) {
return false;
}
return renderToNfc({credential});
}

function _getNFCRenderingTemplate2024({credential}) {
let {renderMethod} = credential;
if(!renderMethod) {
throw new Error('Credential does not contain "renderMethod".');
}

renderMethod = Array.isArray(renderMethod) ? renderMethod : [renderMethod];

let nfcRenderingTemplate2024 = null;
for(const rm of renderMethod) {
if(rm.type === 'NfcRenderingTemplate2024') {
nfcRenderingTemplate2024 = rm;
break;
}
continue;
}

if(nfcRenderingTemplate2024 === null) {
throw new Error('Credential does not support "NfcRenderingTemplate2024".');
}

if(!nfcRenderingTemplate2024.payload) {
throw new Error('NfcRenderingTemplate2024 does not contain "payload".');
}
// export async function toNFCPayload({credential}) {
// const nfcRenderingTemplate2024 =
// _getNFCRenderingTemplate2024({credential});
// const bytes = await _decodeMultibase(nfcRenderingTemplate2024.payload);
// return {bytes};
// }

return nfcRenderingTemplate2024;
export function hasNFCPayload({credential}) {
return supportsNFC({credential});
}

async function _decodeMultibase(input) {
const multibaseHeader = input[0];
const decoder = multibaseDecoders.get(multibaseHeader);
if(!decoder) {
throw new Error(`Multibase header "${multibaseHeader}" not supported.`);
}

const encodedStr = input.slice(1);
return decoder.decode(encodedStr);
}
// export function hasNFCPayload({credential}) {
// try {
// const nfcRenderingTemplate2024 =
// _getNFCRenderingTemplate2024({credential});
// if(!nfcRenderingTemplate2024) {
// return false;
// }

// return true;
// } catch(e) {
// return false;
// }
// }

// function _getNFCRenderingTemplate2024({credential}) {
// let {renderMethod} = credential;
// if(!renderMethod) {
// throw new Error('Credential does not contain "renderMethod".');
// }

// renderMethod = Array.isArray(renderMethod) ? renderMethod : [renderMethod];

// let nfcRenderingTemplate2024 = null;
// for(const rm of renderMethod) {
// if(rm.type === 'NfcRenderingTemplate2024') {
// nfcRenderingTemplate2024 = rm;
// break;
// }
// continue;
// }

// if(nfcRenderingTemplate2024 === null) {
// throw new Error(
// 'Credential does not support "NfcRenderingTemplate2024".');
// }

// if(!nfcRenderingTemplate2024.payload) {
// throw new Error('NfcRenderingTemplate2024 does not contain "payload".');
// }

// return nfcRenderingTemplate2024;
// }

// async function _decodeMultibase(input) {
// const multibaseHeader = input[0];
// const decoder = multibaseDecoders.get(multibaseHeader);
// if(!decoder) {
// throw new Error(`Multibase header "${multibaseHeader}" not supported.`);
// }

// const encodedStr = input.slice(1);
// return decoder.decode(encodedStr);
// }

async function _updateProfileAgentUser({
accessManager, profileAgent, profileAgentContent
Expand Down
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import * as cryptoSuites from './cryptoSuites.js';
import * as exchanges from './exchanges/index.js';
import * as helpers from './helpers.js';
import * as inbox from './inbox.js';
import * as nfcRenderer from './nfcRenderer.js';
import * as presentations from './presentations.js';
import * as users from './users.js';
import * as validator from './validator.js';
import * as zcap from './zcap.js';
export {
ageCredentialHelpers, capabilities, cryptoSuites, exchanges,
helpers, inbox, presentations, users, validator, zcap
helpers, inbox, nfcRenderer, presentations, users, validator, zcap
};
export {
getCredentialStore, getProfileEdvClient, initialize, profileManager
Expand Down
Loading
Loading