From 928eeee291257849c74538fee043a901ba0bf93c Mon Sep 17 00:00:00 2001 From: Michael Wallace Date: Wed, 23 Aug 2023 15:42:15 +1000 Subject: [PATCH 1/3] feat: Add ticket delete method and various other improvements - Add ticketStorage method to delete token from collection by providing tokenId or DecodedToken object. - Change ticket storage to a public readonly property of LocalOutlet. - Define the interface for EventSenderTokensSelected. - Remove redundant EventSenderTokens interface. --- src/client/index.ts | 2 +- src/client/interface.ts | 12 ++++++------ src/client/tokenStore.ts | 12 ++++++++---- src/client/views/token-list.ts | 3 +-- src/outlet/localOutlet.ts | 2 +- src/outlet/ticketStorage.ts | 19 ++++++++++++++++++- 6 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/client/index.ts b/src/client/index.ts index 378737e3..48a59211 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -1094,7 +1094,7 @@ export class Client { ) { requiredParams(type, 'Event type is not defined') - if ((type === 'tokens' || type === 'tokens-selected') && callback) { + if (type === 'tokens-selected' && callback) { this.readTokensFromUrl() } diff --git a/src/client/interface.ts b/src/client/interface.ts index 2b029477..a5a3b023 100644 --- a/src/client/interface.ts +++ b/src/client/interface.ts @@ -5,6 +5,7 @@ import { BrowserDataInterface } from '../utils/support/isSupported' import { WalletConnection } from '../wallet/Web3WalletProvider' import { DecodedToken } from '../outlet/ticketStorage' import { EasSchemaConfig } from '../outlet/interfaces' +import { TokenData } from './tokenStore' export type SupportedBlockchainsParam = 'evm' | 'flow' | 'solana' | 'ultra' export const SignatureSupportedBlockchainsParamList = ['evm', 'flow', 'solana', 'ultra'] @@ -117,7 +118,6 @@ export interface TokenNegotiatorEventsArgs { 'connected-wallet': EventSenderConnectedWallet 'disconnected-wallet': EventSenderDisconnectedWallet 'tokens-selected': EventSenderTokensSelected - tokens: EventSenderTokens 'tokens-loaded': EventSenderTokensLoaded 'network-change': string error: EventSenderError @@ -150,11 +150,11 @@ export interface EventSenderViewChanged { } export interface EventSenderTokensSelected { - selectedTokens: Object -} - -export interface EventSenderTokens { - data: any[] + selectedTokens: { + [collectionId: string]: { + tokens: DecodedToken[] | TokenData[] + } + } } export interface EventSenderTokensLoaded { diff --git a/src/client/tokenStore.ts b/src/client/tokenStore.ts index ffa8aa5b..c226c40c 100644 --- a/src/client/tokenStore.ts +++ b/src/client/tokenStore.ts @@ -1,6 +1,7 @@ import { OffChainTokenConfig, OnChainIssuer, OnChainTokenConfig, SolanaIssuerConfig, UltraIssuerConfig } from './interface' import { logger } from '../utils' +import { DecodedToken } from '../outlet/ticketStorage' interface IssuerLookup { [collectionID: string]: TokenConfig & { timestamp: number } @@ -10,7 +11,8 @@ interface TokenLookup { [issuer: string]: { timestamp: number; tokens: TokenData[] | null } } -interface TokenData { +export interface TokenData { + tokenId: string | number walletAddress?: string // TODO: add more common fields to this interface [key: string]: any @@ -18,6 +20,8 @@ interface TokenData { type TokenConfig = OnChainTokenConfig | OffChainTokenConfig | SolanaIssuerConfig | UltraIssuerConfig +type SelectedTokens = { [collectionId: string]: { tokens: DecodedToken[] | TokenData[] } } + export class TokenStore { public static LOCAL_STORAGE_KEY = 'tn-tokenStore' @@ -28,7 +32,7 @@ export class TokenStore { private tokenLookup: IssuerLookup = {} // TODO: change to disabled tokens - private selectedTokens: any = {} + private selectedTokens: SelectedTokens = {} constructor( private autoEnableTokens: boolean, @@ -173,7 +177,7 @@ export class TokenStore { return null } - public setTokens(issuer: string, tokens: TokenData[]) { + public setTokens(issuer: string, tokens: TokenData[] | DecodedToken[]) { this.tokenData[issuer] = { timestamp: Date.now(), tokens } this.saveTokenStore() @@ -185,7 +189,7 @@ export class TokenStore { return this.selectedTokens } - public setSelectedTokens(selectedTokens: any) { + public setSelectedTokens(selectedTokens: SelectedTokens) { this.selectedTokens = selectedTokens } diff --git a/src/client/views/token-list.ts b/src/client/views/token-list.ts index 356bd9de..71b2f42e 100644 --- a/src/client/views/token-list.ts +++ b/src/client/views/token-list.ts @@ -110,8 +110,7 @@ export class TokenList extends AbstractView { this.viewContainer.querySelectorAll('.mobileToggle-tn').forEach((token: any, index: number) => { if (index === 0) { - selectedTokens[token.dataset.key] = {} - selectedTokens[token.dataset.key]['tokens'] = [] + selectedTokens[token.dataset.key] = { tokens: [] } } if (token.checked === true) { diff --git a/src/outlet/localOutlet.ts b/src/outlet/localOutlet.ts index dc3b0fbd..b89c1a57 100644 --- a/src/outlet/localOutlet.ts +++ b/src/outlet/localOutlet.ts @@ -6,7 +6,7 @@ import { MultiTokenAuthRequest, MultiTokenAuthResult, OutletInterface, OutletIss import { OutletAction } from '../client/messaging' export class LocalOutlet { - protected ticketStorage: TicketStorage + public readonly ticketStorage: TicketStorage constructor(config: OutletInterface) { this.ticketStorage = new TicketStorage(config) diff --git a/src/outlet/ticketStorage.ts b/src/outlet/ticketStorage.ts index 7b4b70bd..2af73ebd 100644 --- a/src/outlet/ticketStorage.ts +++ b/src/outlet/ticketStorage.ts @@ -71,7 +71,7 @@ export interface EasFieldData { } interface TicketStorageSchema { - [collectionHash: string]: StoredTicketRecord[] + [collectionHash: string]: Array } export interface FilterInterface { @@ -167,6 +167,23 @@ export class TicketStorage { }) } + public deleteTicketByDecodedTokenOrId(collectionId: string, decodedTokenOrId: DecodedToken | string) { + const hashes = createIssuerHashArray(this.config.issuers[collectionId]) + const tokenId = typeof decodedTokenOrId === 'string' ? decodedTokenOrId : decodedTokenOrId.tokenId + + for (const hash of hashes) { + for (let i = 0; i < this.ticketCollections[hash].length; i++) { + if (tokenId === this.ticketCollections[hash][0].tokenId) { + this.ticketCollections[hash].splice(i, 1) + this.storeTickets() + return true + } + } + } + + return false + } + /** * Take in a request of collection hashes and return the returns, keyed by client provided ID * @param request From e7cc1438aefc492e5ff9ba1e7bba76bf0c95af5f Mon Sep 17 00:00:00 2001 From: Michael Wallace Date: Fri, 25 Aug 2023 20:28:14 +1000 Subject: [PATCH 2/3] fix: array access for config in deleteTicketByDecodedTokenOrId --- src/outlet/ticketStorage.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/outlet/ticketStorage.ts b/src/outlet/ticketStorage.ts index 2af73ebd..159de839 100644 --- a/src/outlet/ticketStorage.ts +++ b/src/outlet/ticketStorage.ts @@ -168,7 +168,8 @@ export class TicketStorage { } public deleteTicketByDecodedTokenOrId(collectionId: string, decodedTokenOrId: DecodedToken | string) { - const hashes = createIssuerHashArray(this.config.issuers[collectionId]) + const config = this.config.issuers.find((issuer) => issuer.collectionID === collectionId) + const hashes = createIssuerHashArray(config) const tokenId = typeof decodedTokenOrId === 'string' ? decodedTokenOrId : decodedTokenOrId.tokenId for (const hash of hashes) { From 9bd7ffc63dc66d560b606ff9563d79cbc56faa81 Mon Sep 17 00:00:00 2001 From: Nick Taras Date: Tue, 29 Aug 2023 14:37:00 +1000 Subject: [PATCH 3/3] added change log --- CHANGELOG.md | 23 +++++++---------------- package.json | 2 +- src/version.ts | 2 +- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc7a0b05..9ba0c715 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,36 +1,27 @@ > Description -This major version of the Token Negotiator provides simplification to the library interface, and new core features including multi-attestation support. +Patch release to support the upgrade of attestations. ### Upgrade Steps -- Please refer to the migration from 2x to 3x guide. https://tokenscript.gitbook.io/token-negotiator/migrating-from-version-2x-to-3x +- Update NPM package to version 3.0.1 ### Breaking Changes -- Passive Negotiation 'tokens' hook -- Off chain interface changes -- off chain Attestation schema changes (ASN / EAS) +[none] ### New Features -- Support for multi batch EAS & ASN attestation readability and authentication -- Dynamic EAS attestation support -- AlphaWallet provider selection in active UI mode -- Ultra Network support (BETA) -- Removal of Wallet Connect V1 -- Migrated this libraries documentation from README to gitbooks https://tokenscript.gitbook.io/token-negotiator/ -- Added attestation migration support utility function 'migrateLegacyTokenStorage' +- Ability to delete existing attestations ### Bug Fixes -- MetaMask support via Wallet Connect V2 -- attestation.id modal dimensions updated for mobile and via Windows browsers +- Added support for upgrading attestations for live projects (method added via TicketStorage deleteTicketByDecodedTokenOrId) ### Performance Improvements -- Simplified off chain storage of issuer data +[none] **Full Change log**: -https://github.com/TokenScript/token-negotiator/compare/v2.7.1...v3.0.0 +https://github.com/TokenScript/token-negotiator/compare/v3.0.0...v3.0.1 diff --git a/package.json b/package.json index 772b74c5..bd746d54 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tokenscript/token-negotiator", - "version": "3.0.0", + "version": "3.0.1", "description": "Token-negotiator a token attestation bridge between web 2.0 and 3.0.", "module": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/version.ts b/src/version.ts index 01326106..91c28db2 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,2 +1,2 @@ // modified by build process. -export const VERSION = '3.0.0' +export const VERSION = '3.0.1'