Skip to content

Commit

Permalink
Merge pull request #839 from TokenScript/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
nicktaras committed Sep 22, 2023
2 parents 3566202 + 7d70e70 commit 11fd24a
Show file tree
Hide file tree
Showing 9 changed files with 926 additions and 820 deletions.
17 changes: 8 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
> Description
Feature release to support Socios OAuth2 Wallet Provider, additional configuration options and improvments.
Minor release for off chain token attestations

### Upgrade Steps

- Update NPM package to version 3.1.0
- Update NPM package to version 3.1.1

### Breaking Changes

[none]

### New Features

- Added new configuration text to active mode ui options
- Off chain Token user flows now default to re-direct mode, due to all major browsers by default denying to cross origin local storage access via Iframes.
- Added Socios OAuth2 Wallet Provider support via compatbility with a new NPM package (https://www.npmjs.com/package/@tokenscript/token-negotiator-server)
- Upgrade attestation lib to support validation of new EAS off-chain attestation version
- Prevent delete of signedToken property on token object
- Change single token auth to use tokenId instead of sending the entire token object in URL
- Add labels to default ticket schema

### Bug Fixes

- Fix to ensure the validity of attestations when expired
- Show retry for on chain tokens when they fail to resolve the first time
- Off Chain Attestation Toggle button UX fix (for custom EAS tokens)
[none]

### Performance Improvements

[none]

**Full Change log**:

https://github.com/TokenScript/token-negotiator/compare/v3.0.2...v3.1.0
https://github.com/TokenScript/token-negotiator/compare/v3.1.0....v3.1.1
1,678 changes: 898 additions & 780 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tokenscript/token-negotiator",
"version": "3.1.0",
"version": "3.1.1",
"description": "Token-negotiator a token attestation bridge between web 2.0 and 3.0.",
"module": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down 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
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// modified by build process.
export const VERSION = '3.1.0'
export const VERSION = '3.1.1'

1 comment on commit 11fd24a

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage report

St.
Category Percentage Covered / Total
🔴 Statements 37.55% 1399/3726
🔴 Branches 25.22% 422/1673
🔴 Functions 37.78% 184/487
🔴 Lines 37.91% 1190/3139

Test suite run success

84 tests passing in 9 suites.

Report generated by 🧪jest coverage report action from 11fd24a

Please sign in to comment.