Skip to content

Commit

Permalink
aligned interface for on and off chain tokens for authentication of s…
Browse files Browse the repository at this point in the history
…ingle tokens
  • Loading branch information
Nick Taras authored and Nick Taras committed Oct 18, 2023
1 parent 6b3032c commit 0ae18dd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Feature release including multi-hook support, improved UX for off chain token ho
- Multi-Hook support added
- Added selected token issuer keys to 'tokens-selected' event hook
- Explicitly include ethers library availabilty via Token Negotiator library interface `client.externalUtils.evm.ethers`
- Aligned on chain authentication with off chain user interface (for single token authentication on the client side). Multi token on chain authentication is not yet supported (via the current library features).

### Bug Fixes

Expand Down
18 changes: 12 additions & 6 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { MultiTokenAuthRequest, MultiTokenAuthResult, OutletIssuerInterface, Pro
import { AttestationIdClient } from '../outlet/attestationIdClient'
import { EventHookHandler } from './eventHookHandler'
import { ethers } from 'ethers'
import { TokenListItemInterface } from './views/token-list'

if (typeof window !== 'undefined') window.tn = { VERSION }

Expand Down Expand Up @@ -726,6 +727,7 @@ export class Client {

tokens.map((token) => {
token.walletAddress = walletAddress
token.collectionId = issuer.collectionID
return token
})

Expand Down Expand Up @@ -817,10 +819,12 @@ export class Client {

async prepareToAuthenticateToken(authRequest: AuthenticateInterface) {
await this.checkUserAgentSupport('authentication')
const unsignedToken = authRequest?.unsignedToken ?? authRequest
let unsignedToken = authRequest?.unsignedToken
if (!unsignedToken && authRequest.collectionId) unsignedToken = authRequest
const issuer = authRequest?.issuer ?? unsignedToken?.collectionId ?? authRequest?.collectionId
const tokenId = authRequest?.tokenId
requiredParams(issuer && (unsignedToken || tokenId), 'Issuer and unsigned token required.')
console.log('tokenIssuer', issuer, 'unsignedToken', unsignedToken)
requiredParams(issuer && (unsignedToken || tokenId), 'Issuer and unsigned token required MUTLI.')
const config = this.tokenStore.getCurrentIssuers()[issuer]
if (!config) errorHandler('Provided issuer was not found.', 'error', null, null, true, true)
return { unsignedToken, issuer, tokenId }
Expand Down Expand Up @@ -921,13 +925,15 @@ export class Client {
else return this.authenticateToken(authRequest as AuthenticateInterface)
}

async authenticateToken(authRequest: AuthenticateInterface) {
async authenticateToken(authRequest: AuthenticateInterface | any) {
await this.checkUserAgentSupport('authentication')

const { unsignedToken, issuer } = authRequest
const tokenIssuer = issuer ?? unsignedToken.collectionId
const tokenIssuer = authRequest.issuer ?? authRequest.unsignedToken?.collectionId ?? authRequest.collectionId
let unsignedToken = authRequest.unsignedToken
if (!unsignedToken && authRequest.collectionId) unsignedToken = authRequest

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

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

Expand Down
1 change: 1 addition & 0 deletions src/client/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface OnChainTokenConfig extends IssuerConfigInterface {
openSeaSlug?: string
blockchain?: SupportedBlockchainsParam
oAuth2options?: any
abi?: string
}

export interface UltraIssuerConfig extends OnChainTokenConfig {
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.2.0'
export const VERSION = '3.2.12'

0 comments on commit 0ae18dd

Please sign in to comment.