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
62 changes: 3 additions & 59 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/*!
* Copyright (c) 2020-2024 Digital Bazaar, Inc. All rights reserved.
*/
import * as base58 from 'base58-universal';
import * as base64url from 'base64url-universal';
import {renderToNfc, supportsNfc} from './nfcRenderer.js';
import {config} from '@bedrock/web';
import {
Ed25519VerificationKey2020
Expand All @@ -19,11 +18,6 @@ const supportedSignerTypes = new Map([
]
]);

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

export async function createCapabilities({profileId, request}) {
// TODO: validate `request`

Expand Down Expand Up @@ -178,61 +172,11 @@ 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};
return renderToNfc({credential});
}

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);
return supportsNfc({credential});
}

async function _updateProfileAgentUser({
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