Skip to content

Commit

Permalink
Merge pull request #837 from TokenScript/upgrade/attestation-lib2
Browse files Browse the repository at this point in the history
Upgrade attestation lib & various fixes
  • Loading branch information
nicktaras authored Sep 21, 2023
2 parents cfabb82 + 11c8362 commit 2312ef4
Show file tree
Hide file tree
Showing 7 changed files with 914 additions and 774 deletions.
1,641 changes: 896 additions & 745 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@onflow/fcl": "^1.3.2",
"@onflow/types": "^1.0.5",
"@peculiar/asn1-schema": "^2.2.0",
"@tokenscript/attestation": "0.6.0-rc.3",
"@tokenscript/attestation": "0.7.0-rc.1",
"@toruslabs/torus-embed": "^2.2.5",
"@walletconnect/qrcode-modal": "^1.8.0",
"@walletconnect/types": "^2.1.5",
Expand Down
9 changes: 2 additions & 7 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,10 +908,6 @@ export class Client {

requiredParams(tokenIssuer && unsignedToken, 'Issuer and unsigned token required.')

if (unsignedToken.signedToken) {
delete unsignedToken.signedToken
}

const config = this.tokenStore.getCurrentIssuers()[tokenIssuer]

if (!config) errorHandler('Provided issuer was not found.', 'error', null, null, true, true)
Expand Down Expand Up @@ -1142,14 +1138,13 @@ export class Client {
switch (originalAction) {
case OutletAction.GET_PROOF: {
const collectionId: string = this.getDataFromQuery('issuer')
const token: string = this.getDataFromQuery('token')
const decodedToken = JSON.parse(token) as DecodedToken
const tokenId: string = this.getDataFromQuery('tokenId')

const issuerConfig = this.tokenStore.getCurrentIssuers(false)[collectionId] as unknown as OutletIssuerInterface

const issuerHashes = createIssuerHashArray(issuerConfig)

const result = await localOutlet.authenticate(issuerConfig, issuerHashes, decodedToken)
const result = await localOutlet.authenticate(issuerConfig, issuerHashes, tokenId)

await TicketZKProof.validateProof(issuerConfig as unknown as OffChainTokenConfig, result.proof, result.type)

Expand Down
4 changes: 0 additions & 4 deletions src/outlet/attestationIdClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ export class AttestationIdClient {
callbackParams.set('email', email) // TODO: return with attestation.id callback
callbackParams.set(URLNS + 'action', OutletAction.EMAIL_ATTEST_CALLBACK)

// console.log('attestation.id callback params: ', callbackParams.toString())
// callbackParams.set(URLNS + 'issuer', this.tokenConfig.collectionID)
// callbackParams.set(URLNS + 'token', JSON.stringify(this.decodedToken))

const requestor = curParams.get(URLNS + 'requestor')
if (requestor) {
callbackParams.set(URLNS + 'requestor', requestor)
Expand Down
12 changes: 5 additions & 7 deletions src/outlet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,17 @@ export class Outlet extends LocalOutlet {

async sendTokenProof(evtid: string) {
const collectionId: string = this.getDataFromQuery('issuer')
const token: string = this.getDataFromQuery('token')
const tokenId: string = this.getDataFromQuery('tokenId')
const wallet: string = this.getDataFromQuery('wallet')
const address: string = this.getDataFromQuery('address')
requiredParams(token, 'unsigned token is missing')

const decodedToken = JSON.parse(token) as DecodedToken
requiredParams(tokenId, 'tokenId is missing')

const redirect = this.getDataFromQuery('redirect') === 'true' ? window.location.href : false

try {
const issuer = this.getIssuerConfigById(collectionId)

const ticketRecord = await this.ticketStorage.getStoredTicketFromDecodedTokenOrId(createIssuerHashArray(issuer), decodedToken)
const ticketRecord = await this.ticketStorage.getStoredTicketFromDecodedTokenOrId(createIssuerHashArray(issuer), tokenId)

const attestIdClient = new AttestationIdClient(
issuer.attestationOrigin,
Expand All @@ -240,7 +238,7 @@ export class Outlet extends LocalOutlet {
const idAttestation = await attestIdClient.getIdentifierAttestation(ticketRecord.id, wallet, address, {
action: OutletAction.GET_PROOF,
issuer: collectionId,
token: JSON.stringify(decodedToken),
tokenId,
})

const tokenProof = await getUseToken(issuer, idAttestation.attestation, idAttestation.identifierSecret, ticketRecord)
Expand All @@ -253,7 +251,7 @@ export class Outlet extends LocalOutlet {
params.set(this.getCallbackUrlKey('issuer'), collectionId)
params.set(this.getCallbackUrlKey('attestation'), tokenProof.proof as string)
params.set(this.getCallbackUrlKey('type'), ticketRecord.type)
params.set(this.getCallbackUrlKey('token'), token)
params.set(this.getCallbackUrlKey('tokenId'), tokenId)

requesterURL.hash = params.toString()
window.location.href = requesterURL.href
Expand Down
6 changes: 3 additions & 3 deletions src/outlet/localOutlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ export class LocalOutlet {
async authenticate(
tokenConfig: OutletIssuerInterface,
issuerHashes: string[],
decodedToken: DecodedToken,
tokenId: string,
address?: string,
wallet?: string,
redirectMode: false | string = false,
) {
const ticketRecord = await this.ticketStorage.getStoredTicketFromDecodedTokenOrId(issuerHashes, decodedToken)
const ticketRecord = await this.ticketStorage.getStoredTicketFromDecodedTokenOrId(issuerHashes, tokenId)

const attestIdClient = new AttestationIdClient(tokenConfig.attestationOrigin, undefined, redirectMode)
const idAttestation = await attestIdClient.getIdentifierAttestation(ticketRecord.id, wallet, address, {
action: OutletAction.GET_PROOF,
issuer: tokenConfig.collectionID,
token: JSON.stringify(decodedToken),
tokenId,
})

return await getUseToken(tokenConfig, idAttestation.attestation, idAttestation.identifierSecret, ticketRecord)
Expand Down
14 changes: 7 additions & 7 deletions src/outlet/ticketStorage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { EasTicketAttestation, TicketSchema } from '@tokenscript/attestation/dist/eas/EasTicketAttestation'
import { EasTicketAttestation, SchemaField, TicketSchema } from '@tokenscript/attestation/dist/eas/EasTicketAttestation'
import { KeyPair } from '@tokenscript/attestation/dist/libs/KeyPair'
import { base64ToUint8array, createIssuerHashArray, createOffChainCollectionHash, errorHandler, IssuerHashMap, logger } from '../utils'
import { Ticket } from '@tokenscript/attestation/dist/Ticket'
import { EasFieldDefinition, OutletInterface, OutletIssuerInterface } from './interfaces'
import { DevconTicket, SignedDevconTicket } from '@tokenscript/attestation/dist/asn1/shemas/SignedDevconTicket'
import { AsnParser } from '@peculiar/asn1-schema'
import { decodeBase64ZippedBase64 } from '@tokenscript/attestation/dist/eas/AttestationUrl'
import { decodeBase64ZippedBase64 } from '@ethereum-attestation-service/eas-sdk'
import { SignedOffchainAttestation } from '@ethereum-attestation-service/eas-sdk/dist/offchain/offchain'
import { DEFAULT_RPC_MAP } from '../core/constants'
import { TokenStore } from '../client/tokenStore'
Expand Down Expand Up @@ -78,12 +78,12 @@ export interface FilterInterface {
[key: string]: any
}

export const DEFAULT_EAS_SCHEMA: TicketSchema = {
export const DEFAULT_EAS_SCHEMA: { fields: (SchemaField & { label?: string })[] } = {
fields: [
{ name: 'eventId', type: 'string' },
{ name: 'ticketId', type: 'string' },
{ name: 'ticketClass', type: 'uint8' },
{ name: 'commitment', type: 'bytes', isCommitment: true },
{ name: 'eventId', type: 'string', label: 'Event ID' },
{ name: 'ticketId', type: 'string', label: 'Ticket ID' },
{ name: 'ticketClass', type: 'uint8', label: 'Ticket Class' },
{ name: 'commitment', type: 'bytes', isCommitment: true, label: 'Email commitment' },
],
}

Expand Down

0 comments on commit 2312ef4

Please sign in to comment.