-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New QR code provider plugin. Can generate both SIOPv2 and DIDCo…
…mmv2 OOB QRs. Support for text generation and React QR codes as SVG
- Loading branch information
Showing
15 changed files
with
436 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,22 @@ | ||
import { AcceptMode, GoalCode, OobPayload, OobQRProps, QRType } from '../src' | ||
import { OutOfBandMessage } from '../src/agent/qr-utils/outOfBandMessage' | ||
import base64url from 'base64url' | ||
|
||
const oobQRProps: OobQRProps = { | ||
oobBaseUrl: 'https://example.com/?oob=', | ||
type: QRType.DID_AUTH_SIOP_V2, | ||
id: '599f3638-b563-4937-9487-dfe55099d900', | ||
from: 'did:key:zrfdjkgfjgfdjk', | ||
body: { | ||
goalCode: GoalCode.STREAMLINED_VP, | ||
accept: [AcceptMode.SIOPV2_WITH_OIDC4VP], | ||
}, | ||
onGenerate: (oobQRProps: OobQRProps, payload: OobPayload) => { | ||
console.log(payload) | ||
}, | ||
bgColor: 'white', | ||
fgColor: 'black', | ||
level: 'L', | ||
size: 128, | ||
title: 'title2021120903', | ||
} | ||
import { DidCommOutOfBandMessage } from '../src/agent/utils' | ||
import { oobInvitation } from './shared/fixtures' | ||
|
||
describe('SSI QR Code', () => { | ||
it('should create payload object', async () => { | ||
const payload = OutOfBandMessage.createPayload(oobQRProps) | ||
// const encoded = OutOfBandMessage.encode(payload) | ||
// const url = oobQRProps.oobBaseUrl + encoded | ||
|
||
expect(payload).toMatchObject({ | ||
body: { accept: ['siopv2+oidc4vp'], goalCode: 'streamlined-vp' }, | ||
from: 'did:key:zrfdjkgfjgfdjk', | ||
id: '599f3638-b563-4937-9487-dfe55099d900', | ||
type: 'siopv2', | ||
}) | ||
}) | ||
|
||
it('should create json value', async () => { | ||
const payload = OutOfBandMessage.createPayload(oobQRProps) | ||
const json = OutOfBandMessage.toJson(payload) | ||
const json = DidCommOutOfBandMessage.toJson(oobInvitation) | ||
expect(json).toMatch( | ||
'{"type":"siopv2","id":"599f3638-b563-4937-9487-dfe55099d900","from":"did:key:zrfdjkgfjgfdjk","body":{"goal-code":"streamlined-vp","accept":["siopv2+oidc4vp"]}}' | ||
'{"type":"https://didcomm.org/out-of-band/2.0/invitation","id":"599f3638-b563-4937-9487-dfe55099d900","from":"did:key:zrfdjkgfjgfdjk","body":{"goal_code":"streamlined-vp","accept":["didcomm/v2"]}}' | ||
) | ||
}) | ||
|
||
it('should url encode and decode', async () => { | ||
const payload = OutOfBandMessage.createPayload(oobQRProps) | ||
const urlEncoded = OutOfBandMessage.urlEncode(payload) | ||
const urlEncoded = DidCommOutOfBandMessage.urlEncode(oobInvitation) | ||
expect(urlEncoded).toMatch( | ||
'eyJ0eXBlIjoic2lvcHYyIiwiaWQiOiI1OTlmMzYzOC1iNTYzLTQ5MzctOTQ4Ny1kZmU1NTA5OWQ5MDAiLCJmcm9tIjoiZGlkOmtleTp6cmZkamtnZmpnZmRqayIsImJvZHkiOnsiZ29hbC1jb2RlIjoic3RyZWFtbGluZWQtdnAiLCJhY2NlcHQiOlsic2lvcHYyK29pZGM0dnAiXX19' | ||
'eyJ0eXBlIjoiaHR0cHM6Ly9kaWRjb21tLm9yZy9vdXQtb2YtYmFuZC8yLjAvaW52aXRhdGlvbiIsImlkIjoiNTk5ZjM2MzgtYjU2My00OTM3LTk0ODctZGZlNTUwOTlkOTAwIiwiZnJvbSI6ImRpZDprZXk6enJmZGprZ2ZqZ2ZkamsiLCJib2R5Ijp7ImdvYWxfY29kZSI6InN0cmVhbWxpbmVkLXZwIiwiYWNjZXB0IjpbImRpZGNvbW0vdjIiXX19' | ||
) | ||
expect(base64url.decode(urlEncoded)).toMatch( | ||
'{"type":"siopv2","id":"599f3638-b563-4937-9487-dfe55099d900","from":"did:key:zrfdjkgfjgfdjk","body":{"goal-code":"streamlined-vp","accept":["siopv2+oidc4vp"]}}' | ||
'{"type":"https://didcomm.org/out-of-band/2.0/invitation","id":"599f3638-b563-4937-9487-dfe55099d900","from":"did:key:zrfdjkgfjgfdjk","body":{"goal_code":"streamlined-vp","accept":["didcomm/v2"]}}' | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { | ||
CreateElementArgs, | ||
CreateValueArgs, | ||
DIDCommV2OOBInvitation, | ||
DIDCommV2OOBInvitationData, | ||
QRData, | ||
QRRenderingProps, | ||
QRType, | ||
SIOPv2DataWithScheme, | ||
ValueResult, | ||
} from '../../src' | ||
import { render } from '@testing-library/react' | ||
import * as React from 'react' | ||
|
||
export const renderingProps: QRRenderingProps = { | ||
bgColor: 'white', | ||
fgColor: 'black', | ||
level: 'L', | ||
size: 128, | ||
title: 'title2021120903', | ||
} | ||
|
||
export const oobInvitation: DIDCommV2OOBInvitation = { | ||
type: QRType.DIDCOMM_V2_OOB_INVITATION, | ||
id: '599f3638-b563-4937-9487-dfe55099d900', | ||
from: 'did:key:zrfdjkgfjgfdjk', | ||
body: { | ||
goal_code: 'streamlined-vp', | ||
accept: ['didcomm/v2'], | ||
}, | ||
} | ||
|
||
export const oobInvitationData: DIDCommV2OOBInvitationData = { | ||
oobInvitation, | ||
baseURI: 'https://example.com/?_oob=', | ||
} | ||
|
||
export const oobInvitationCreateValue: CreateValueArgs<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData> = { | ||
data: { | ||
object: oobInvitationData, | ||
type: QRType.DIDCOMM_V2_OOB_INVITATION, | ||
id: '1234', | ||
}, | ||
onGenerate: (result: ValueResult<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData>) => { | ||
console.log(JSON.stringify(result, null, 2)) | ||
}, | ||
} | ||
|
||
export const oobInvitationCreateElement: CreateElementArgs<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData> = { | ||
data: { | ||
object: oobInvitationData, | ||
type: QRType.DIDCOMM_V2_OOB_INVITATION, | ||
id: '1234', | ||
}, | ||
renderingProps, | ||
onGenerate: (result: ValueResult<QRType.DIDCOMM_V2_OOB_INVITATION, DIDCommV2OOBInvitationData>) => { | ||
render(<div data-testid="test-div">{result.data.object.oobInvitation.from}</div>) | ||
console.log(result.value) | ||
}, | ||
} | ||
|
||
const siopv2Object: SIOPv2DataWithScheme = { | ||
scheme: 'openid-vc', | ||
requestUri: 'https://test.com?id=23', | ||
} | ||
const siopv2Data: QRData<QRType.SIOPV2, SIOPv2DataWithScheme> = { | ||
object: siopv2Object, | ||
type: QRType.SIOPV2, | ||
id: '456', | ||
} | ||
export const siopv2CreateValue: CreateValueArgs<QRType.SIOPV2, SIOPv2DataWithScheme> = { | ||
data: siopv2Data, | ||
onGenerate: (result: ValueResult<QRType.SIOPV2, SIOPv2DataWithScheme>) => { | ||
console.log(JSON.stringify(result, null, 2)) | ||
}, | ||
} | ||
|
||
export const siopv2CreateElement: CreateElementArgs<QRType.SIOPV2, SIOPv2DataWithScheme> = { | ||
data: siopv2Data, | ||
renderingProps, | ||
onGenerate: (result: ValueResult<QRType.SIOPV2, SIOPv2DataWithScheme>) => { | ||
render(<div data-testid="test-div-siopv2">{result.data.object.requestUri}</div>) | ||
console.log(result.value) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.