Skip to content

Commit

Permalink
fix: Various fixes for attestation
Browse files Browse the repository at this point in the history
  • Loading branch information
micwallace committed Oct 20, 2023
1 parent 62527f5 commit 6d8d893
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 40 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.7.0-rc.1",
"@tokenscript/attestation": "0.7.0-rc.2",
"@toruslabs/torus-embed": "^2.2.5",
"@walletconnect/qrcode-modal": "^1.8.0",
"@walletconnect/types": "^2.1.5",
Expand Down
9 changes: 8 additions & 1 deletion src/client/auth/ticketZKProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ export class TicketZKProof extends AbstractAuthentication implements Authenticat
if (type === 'eas') {
const schema = issuerConfig.eas ? { fields: issuerConfig.eas.fields } : DEFAULT_EAS_SCHEMA
const easZkProof = new EasZkProof(schema, { ...DEFAULT_RPC_MAP, ...ethRPCMap })
await easZkProof.validateUseTicket(proof, issuerConfig.base64attestorPubKey, issuerConfig.base64senderPublicKeys, ethAddress)
await easZkProof.validateUseTicket(
proof,
issuerConfig.base64attestorPubKey,
issuerConfig.base64senderPublicKeys,
ethAddress,
'asn',
'asn',
)
} else {
Authenticator.validateUseTicket(proof, issuerConfig.base64attestorPubKey, issuerConfig.base64senderPublicKeys, ethAddress)
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ export class Client {
}
}
} catch (error) {
errorHandler('popup error', 'error', () => this.eventSender('error', { issuer, error }), null, true, false)
errorHandler(error, 'error', () => this.eventSender('error', { issuer, error }), null, true, false)
continue
}

Expand Down
51 changes: 26 additions & 25 deletions src/client/views/select-issuers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ export class SelectIssuers extends AbstractView {
new IconView(elem, params).render()
}

this.issuerListContainer.addEventListener('click', (e: any) => {
this.issuerListContainer.addEventListener('click', async (e: any) => {
if (e.target.classList.contains('connect-btn-tn')) {
this.connectTokenIssuer(e)
this.client.getTokenStore().setIncrementCollectionLoadAttempts(e.target.dataset.issuer);
await this.connectTokenIssuer(e)
this.client.getTokenStore().setIncrementCollectionLoadAttempts(e.target.dataset.issuer)
} else if (e.target.classList.contains('tokens-btn-tn')) {
const issuer = e.target.parentNode.dataset.issuer
this.navigateToTokensView(issuer)
Expand All @@ -171,11 +171,14 @@ export class SelectIssuers extends AbstractView {

issuerConnectMarkup(title: string, image: string | undefined, issuer: string, tokens: any[], data: Issuer) {
let buttonText = ''
const collectLoadAttempts = this.client.getTokenStore().getCollectionLoadAttempts(issuer);
let issuerButtonText = this.params.options?.loadAction ?? "Load Collection";
if (collectLoadAttempts >= 1) issuerButtonText = this.params.options?.repeatAction ?? 'Retry';
const collectLoadAttempts = this.client.getTokenStore().getCollectionLoadAttempts(issuer)
let issuerButtonText = this.params.options?.loadAction ?? 'Load Collection'
if (collectLoadAttempts >= 1) issuerButtonText = this.params.options?.repeatAction ?? 'Retry'
// @ts-ignore
if (tokens?.length) buttonText = data?.fungible ? this.params.options?.balanceFoundEvent ?? 'Balance found' : `${tokens.length} ${this.params.options?.nftsFoundEvent ?? 'Token(s) Available'}`
if (tokens?.length)
buttonText = data?.fungible

Check failure on line 179 in src/client/views/select-issuers.ts

View workflow job for this annotation

GitHub Actions / tn-p1 / tn-p1

Property 'fungible' does not exist on type 'Issuer'.
? this.params.options?.balanceFoundEvent ?? 'Balance found'
: `${tokens.length} ${this.params.options?.nftsFoundEvent ?? 'Token(s) Available'}`
return `
<li class="issuer-connect-banner-tn" data-issuer="${issuer}" role="menuitem">
<div tabindex="0" style="display: flex; align-items: center;">
Expand All @@ -188,10 +191,11 @@ export class SelectIssuers extends AbstractView {
data-issuer="${issuer}"
${this.client.issuersLoaded === true ? '' : 'disabled'}
>
${this.client.issuersLoaded === true
? issuerButtonText
: '<div class="lds-ellipsis lds-ellipsis-sm" style=""><div></div><div></div><div></div><div></div></div>'
}
${
this.client.issuersLoaded === true
? issuerButtonText
: '<div class="lds-ellipsis lds-ellipsis-sm" style=""><div></div><div></div><div></div><div></div></div>'
}
</button>
<button aria-label="tokens available from token issuer ${issuer}"
aria-haspopup="true"
Expand All @@ -213,28 +217,24 @@ export class SelectIssuers extends AbstractView {
}

async autoLoadTokens(refresh = false) {
await this.client.tokenAutoLoad(
this.issuerLoading.bind(this),
this.issuerLoadingComplete.bind(this),
refresh,
)
await this.client.tokenAutoLoad(this.issuerLoading.bind(this), this.issuerLoadingComplete.bind(this), refresh)
}

issuerLoadingComplete(issuer: string, tokens: any[]) {
if (!tokens?.length) {
this.issuerDidntConnect(issuer);
this.issuerDidntConnect(issuer)
} else {
this.issuerConnected(issuer, tokens, false)
}
}

issuerDidntConnect(issuer: string, showNotification = false) {
const collectLoadAttempts = this.client.getTokenStore().getCollectionLoadAttempts(issuer);
let issuerButtonText = this.params.options?.loadAction ?? "Load Collection";
if (collectLoadAttempts >= 1) issuerButtonText = this.params.options?.repeatAction ?? 'Retry';
const collectLoadAttempts = this.client.getTokenStore().getCollectionLoadAttempts(issuer)
let issuerButtonText = this.params.options?.loadAction ?? 'Load Collection'
if (collectLoadAttempts >= 1) issuerButtonText = this.params.options?.repeatAction ?? 'Retry'
const connectBtn = this.issuerListContainer.querySelector(`[data-issuer="${issuer}"] .connect-btn-tn`)
if (connectBtn) {
connectBtn.innerHTML = issuerButtonText;
connectBtn.innerHTML = issuerButtonText
connectBtn.style.display = 'block'
}
if (showNotification) {
Expand Down Expand Up @@ -266,7 +266,7 @@ export class SelectIssuers extends AbstractView {
this.ui.dismissLoader()

if (!tokens?.length) {
this.issuerDidntConnect(issuer, true);
this.issuerDidntConnect(issuer, true)
return
}

Expand All @@ -284,7 +284,6 @@ export class SelectIssuers extends AbstractView {
connectBtn.innerHTML = '<div class="lds-ellipsis lds-ellipsis-sm" style=""><div></div><div></div><div></div><div></div></div>'
connectBtn.style.display = 'block'
}

}

issuerConnected(issuer: string, tokens: any[], showTokens = true) {
Expand All @@ -302,7 +301,9 @@ export class SelectIssuers extends AbstractView {
let issuers = this.client.getTokenStore().getCurrentIssuers()

tokenBtn.innerHTML =
tokens.length && issuers[issuer].fungible ? this.params.options.balanceFoundEvent ?? 'Balance found' : `${tokens.length} ${this.params.options?.nftsFoundEvent ?? 'Token(s) Available'}`
tokens.length && issuers[issuer].fungible
? this.params.options.balanceFoundEvent ?? 'Balance found'
: `${tokens.length} ${this.params.options?.nftsFoundEvent ?? 'Token(s) Available'}`
tokenBtn.setAttribute('aria-label', `Navigate to select from ${tokens.length} of your ${issuer} tokens`)
tokenBtn.setAttribute('tabIndex', 1)

Expand Down Expand Up @@ -346,7 +347,7 @@ export class SelectIssuers extends AbstractView {

if (config.onChain === false) {
const { title, image } = config
const tokenId = t.tokenId ?? t.ticketId ?? i.toString();
const tokenId = t.tokenId ?? t.ticketId ?? i.toString()
tokens.push(<TokenListItemInterface>{
data: t,
tokenIssuerKey: issuer,
Expand Down
9 changes: 6 additions & 3 deletions src/outlet/ticketStorage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { EasTicketAttestation, SchemaField } from '@tokenscript/attestation/dist/eas/EasTicketAttestation'
import {
EasTicketAttestation,
SchemaField,
SignedOffchainAttestation,
decodeBase64ZippedBase64,
} 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 '@ethereum-attestation-service/eas-sdk'
import { SignedOffchainAttestation } from '@ethereum-attestation-service/eas-sdk/dist/offchain/offchain'
import { DEFAULT_RPC_MAP, LOCAL_STORAGE_TOKEN_KEY } from '../constants'
import { TokenStore } from '../client/tokenStore'
export type TokenType = 'asn' | 'eas'
Expand Down

0 comments on commit 6d8d893

Please sign in to comment.