Skip to content

Commit

Permalink
chore: Rename some methods and update package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Mar 5, 2024
1 parent 0fee06f commit cddfb96
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 115 deletions.
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
"@sphereon/ssi-sdk-ext.did-utils": "0.16.1-next.2",
"@sphereon/ssi-sdk-ext.key-manager": "0.16.1-next.2",
"@sphereon/ssi-sdk-ext.kms-local": "0.16.1-next.2",
"@sphereon/ssi-sdk.contact-manager": "0.18.2-next.95",
"@sphereon/ssi-sdk.core": "0.18.2-next.95",
"@sphereon/ssi-sdk.data-store": "0.18.2-next.95",
"@sphereon/ssi-sdk.issuance-branding": "0.18.2-next.95",
"@sphereon/ssi-sdk.siopv2-oid4vp-op-auth": "0.18.2-next.95",
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.18.2-next.95",
"@sphereon/ssi-sdk.event-logger": "0.18.2-next.95",
"@sphereon/ssi-sdk.oid4vci-holder": "0.18.2-next.95",
"@sphereon/ssi-types": "0.18.2-next.95",
"@sphereon/ssi-sdk.contact-manager": "0.19.0",
"@sphereon/ssi-sdk.core": "0.19.0",
"@sphereon/ssi-sdk.data-store": "0.19.0",
"@sphereon/ssi-sdk.issuance-branding": "0.19.0",
"@sphereon/ssi-sdk.siopv2-oid4vp-op-auth": "0.19.0",
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.19.0",
"@sphereon/ssi-sdk.event-logger": "0.19.0",
"@sphereon/ssi-sdk.oid4vci-holder": "0.19.0",
"@sphereon/ssi-types": "0.19.0",
"@sphereon/ui-components.core": "0.1.3-unstable.123",
"@sphereon/ui-components.ssi-react-native": "0.1.3-unstable.123",
"@transmute/lds-ecdsa-secp256k1-recovery2020": "^0.0.7",
Expand Down Expand Up @@ -247,13 +247,13 @@
"ajv": "^8.12.0",
"@sphereon/isomorphic-argon2": "1.0.1",
"@sphereon/did-auth-siop": "0.6.0",
"@sphereon/ssi-types": "0.18.2-next.95",
"@sphereon/ssi-sdk.core": "0.18.2-next.95",
"@sphereon/ssi-types": "0.19.0",
"@sphereon/ssi-sdk.core": "0.19.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.16.1-next.2",
"@sphereon/ssi-sdk-ext.kms-local": "0.16.1-next.2",
"@sphereon/ssi-sdk-ext.key-manager": "0.16.1-next.2",
"@sphereon/ssi-sdk.data-store": "0.18.2-next.95",
"@sphereon/ssi-sdk.contact-manager": "0.18.2-next.95",
"@sphereon/ssi-sdk.data-store": "0.19.0",
"@sphereon/ssi-sdk.contact-manager": "0.19.0",
"@sphereon/oid4vci-client": "0.10.0",
"@sphereon/oid4vci-common": "0.10.0",
"@sphereon/pex": "3.3.0",
Expand Down
3 changes: 2 additions & 1 deletion src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
OID4VCIHolder,
OnContactIdentityCreatedArgs,
OnCredentialStoredArgs,
OnGetCredentialsArgs,
} from '@sphereon/ssi-sdk.oid4vci-holder';
import OpenId4VcIssuanceProvider, {CredentialToAccept} from '../providers/credential/OpenId4VcIssuanceProvider';
import {ADD_IDENTITY_SUCCESS} from '../types/store/contact.action.types';
Expand Down Expand Up @@ -141,7 +142,7 @@ const agent = createAgent<
keyStore: privateKeyStore,
}),
new OID4VCIHolder({
onGetCredentials: new OpenId4VcIssuanceProvider().getCredentials,
onGetCredentials: async (args: OnGetCredentialsArgs) => new OpenId4VcIssuanceProvider().getCredentials(args),
onContactIdentityCreated: async (args: OnContactIdentityCreatedArgs): Promise<void> => {
store.dispatch({type: ADD_IDENTITY_SUCCESS, payload: args});
},
Expand Down
11 changes: 7 additions & 4 deletions src/providers/credential/OpenId4VcIssuanceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
SupportedDidMethodEnum,
} from '../../types';
// FIXME: This file needs a complete overhaul. Much needs to move the SDK and should be called by xstate
import {KeyTypeFromCryptographicSuite, SignatureAlgorithmFromKey} from '../../utils';
import {keyTypeFromCryptographicSuite, signatureAlgorithmFromKey} from '../../utils';
import {credentialLocaleBrandingFrom} from '../../utils/mappers/branding/OIDC4VCIBrandingMapper';

const debug: Debugger = Debug(`${APP_ID}:openid4vci`);
Expand Down Expand Up @@ -298,7 +298,7 @@ class OpenId4VcIssuanceProvider {
return Promise.reject(Error(`Cannot get credential issuance options`));
}
const {identifier, key, kid} = await this.getIdentifier({issuanceOpt});
const alg: SignatureAlgorithmEnum = SignatureAlgorithmFromKey(key);
const alg: SignatureAlgorithmEnum = signatureAlgorithmFromKey(key);

const callbacks: ProofOfPossessionCallbacks<DIDDocument> = {
signCallback: (jwt: Jwt, kid?: string) => {
Expand Down Expand Up @@ -327,7 +327,10 @@ class OpenId4VcIssuanceProvider {

try {
// We need to make sure we have acquired the access token
await clientInstance.acquireAccessToken({pin, authorizationResponse: this.authorizationCodeResponse});
if (!clientInstance.clientId) {
clientInstance.clientId = issuanceOpt.identifier.did;
}
await clientInstance.acquireAccessToken({clientId: clientInstance.clientId, pin, authorizationResponse: this.authorizationCodeResponse});
// @ts-ignore
debug(`credential type: ${JSON.stringify(issuanceOpt.types)}, format: ${issuanceOpt.format}, kid: ${kid}, alg: ${alg}`);

Expand Down Expand Up @@ -519,7 +522,7 @@ class OpenId4VcIssuanceProvider {
...credentialSupported,
didMethod,
format: credentialSupported.format,
keyType: client.isEBSI() ? 'Secp256r1' : KeyTypeFromCryptographicSuite(cryptographicSuite),
keyType: client.isEBSI() ? 'Secp256r1' : keyTypeFromCryptographicSuite(cryptographicSuite),
...(client.isEBSI() && {codecName: 'EBSI'}),
} as IIssuanceOpts;
const identifierOpts = await this.getIdentifier({issuanceOpt});
Expand Down
4 changes: 2 additions & 2 deletions src/services/signatureService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {createJWT, Signer} from 'did-jwt';

import {keyManagerSign} from '../agent';
import {ISignJwtArgs} from '../types';
import {SignatureAlgorithmFromKey} from '../utils/KeyUtils';
import {signatureAlgorithmFromKey} from '../utils/KeyUtils';

export const signJWT = async (args: ISignJwtArgs): Promise<string> => {
const options = {
Expand All @@ -18,7 +18,7 @@ const getSigner = (identifier: IIdentifier): Signer => {
// TODO currently we assume an identifier only has one key
const key = identifier.keys[0];
// TODO See if this is mandatory for a correct JWT
const algorithm = SignatureAlgorithmFromKey(key);
const algorithm = signatureAlgorithmFromKey(key);

return async (data: string | Uint8Array): Promise<string> => {
const input = data instanceof Object.getPrototypeOf(Uint8Array) ? new TextDecoder().decode(data as Uint8Array) : (data as string);
Expand Down
8 changes: 4 additions & 4 deletions src/utils/KeyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {IKey, TKeyType} from '@veramo/core';

import {SignatureAlgorithmEnum} from '../providers/credential/OpenId4VcIssuanceProvider';

export const SignatureAlgorithmFromKeyType = (type: TKeyType) => {
export const signatureAlgorithmFromKeyType = (type: TKeyType) => {
switch (type) {
case 'Ed25519':
case 'X25519':
Expand All @@ -16,12 +16,12 @@ export const SignatureAlgorithmFromKeyType = (type: TKeyType) => {
}
};

export const SignatureAlgorithmFromKey = (key: IKey) => {
return SignatureAlgorithmFromKeyType(key.type);
export const signatureAlgorithmFromKey = (key: IKey) => {
return signatureAlgorithmFromKeyType(key.type);
};

// TODO improve this conversion for jwt and jsonld, not a fan of current structure
export const KeyTypeFromCryptographicSuite = (suite: string): TKeyType => {
export const keyTypeFromCryptographicSuite = (suite: string): TKeyType => {
switch (suite) {
case 'EdDSA':
case 'Ed25519Signature2018':
Expand Down
4 changes: 3 additions & 1 deletion src/utils/mappers/credential/CredentialMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import {ICredentialDetailsRow, ICredentialSummary} from '../../../types';
import {getCredentialStatus, translateCorrelationIdToName} from '../../CredentialUtils';
import {EPOCH_MILLISECONDS} from '../../DateUtils';
import {getImageSize, isImage} from '../../ImageUtils';
import {mapLanguageValues} from '@sphereon/ssi-types';

const toCredentialDetailsRow = async (object: Record<string, any>): Promise<ICredentialDetailsRow[]> => {
let rows: ICredentialDetailsRow[] = [];
const mappedValues = mapLanguageValues(object);
// eslint-disable-next-line prefer-const
for (let [key, value] of Object.entries(object)) {
for (let [key, value] of Object.entries(mappedValues)) {
// TODO fix hacking together the image
if (key.toLowerCase().includes('image')) {
const image = typeof value === 'string' ? value : value.id;
Expand Down
Loading

0 comments on commit cddfb96

Please sign in to comment.