-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #867 from TokenScript/release/3.2.0
Release/3.2.0
- Loading branch information
Showing
5 changed files
with
62 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Client } from '../index' | ||
|
||
describe('src spec', () => { | ||
test('ensure client is defined', async () => { | ||
expect(Client).toBeDefined() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
// @ts-nocheck | ||
import { AbstractAuthentication } from '../auth/abstractAuthentication' | ||
import { AttestedAddress } from '../auth/attestedAddress' | ||
import { Client } from '../index' | ||
import { TicketZKProof } from '../auth/ticketZKProof' | ||
import { URLNS } from '../../core/messaging' | ||
import { Outlet, defaultConfig } from '../../outlet/index' | ||
import { Client as client_2_0, Outlet as outlet_2_0 } from 'tn2_0' | ||
import { Client as client_2_2, Outlet as outlet_2_2 } from 'tn2_2' | ||
import { OffChainTokenConfig } from '../interface' | ||
import { TextEncoder, TextDecoder } from 'util'; | ||
|
||
function delay(time) { | ||
return new Promise((resolve) => setTimeout(resolve, time)) | ||
} | ||
Object.assign(global, { TextDecoder, TextEncoder }); | ||
|
||
let tokenIssuer: OffChainTokenConfig = { | ||
collectionID: 'devcon', | ||
|
@@ -27,37 +21,8 @@ let tokenIssuer: OffChainTokenConfig = { | |
base64attestorPubKey: '', | ||
} | ||
|
||
let tokenIssuer2: OffChainTokenConfig = { | ||
collectionID: 'edcon', | ||
title: 'Devcon', | ||
onChain: false, | ||
tokenOrigin: 'http://some.url/', | ||
attestationOrigin: 'https://stage.attestation.id/', | ||
unEndPoint: 'https://crypto-verify.herokuapp.com/use-devcon-ticket', | ||
image: 'https://raw.githubusercontent.com/TokenScript/token-negotiator/main/mock-images/devcon.svg', | ||
base64senderPublicKeys: { | ||
10: 'MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEAGJAHCiHbrCNAY9fAMdom4dGD6v/KkTIgRCkwLCjXFTkXWGrCEXHaZ8kWwdqlu0oYCrNQ2vdlqOl0s26/LzO8A==|MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEAGJAHCiHbrCNAY9fAMdom4dGD6v/KkTIgRCkwLCjXFTkXWGrCEXHaZ8kWwdqlu0oYCrNQ2vdlqOl0s26/LzO8B==', | ||
}, | ||
base64attestorPubKey: '', | ||
} | ||
|
||
let tokenIssuer3: OffChainTokenConfig = { | ||
collectionID: 'devconnect', | ||
title: 'Devcon', | ||
onChain: false, | ||
tokenOrigin: 'http://some.url/', | ||
attestationOrigin: 'https://stage.attestation.id/', | ||
unEndPoint: 'https://crypto-verify.herokuapp.com/use-devcon-ticket', | ||
image: 'https://raw.githubusercontent.com/TokenScript/token-negotiator/main/mock-images/devcon.svg', | ||
base64senderPublicKeys: { | ||
55: 'MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEAGJAHCiHbrCNAY9fAMdom4dGD6v/KkTIgRCkwLCjXFTkXWGrCEXHaZ8kWwdqlu0oYCrNQ2vdlqOl0s26/LzO8A==', | ||
}, | ||
base64attestorPubKey: '', | ||
} | ||
|
||
const config = { | ||
type: 'passive', | ||
// requred to force redirect mode for Client 2.2 | ||
enableOffChainRedirectMode: true, | ||
issuers: [tokenIssuer], | ||
} | ||
|
@@ -126,6 +91,7 @@ class LocalStorageMock { | |
} | ||
|
||
describe('client spec', () => { | ||
|
||
test('tokenNegotiatorClient a failed new instance of client - missing issuers key', () => { | ||
let client = new Client({ | ||
type: 'passive', | ||
|
@@ -137,6 +103,54 @@ describe('client spec', () => { | |
}) | ||
}) | ||
|
||
test('client library interface method switch theme can be used', () => { | ||
const tokenNegotiatorClient = getOffChainConfigClient() | ||
let client = new Client({ | ||
type: 'active', | ||
issuers: tokenNegotiatorClient.getTokenStore().getCurrentIssuers(), | ||
options: {}, | ||
}) | ||
client.negotiate().then(() => { | ||
client.switchTheme('dark'); | ||
}); | ||
}) | ||
|
||
test('client library can add token via magic link', () => { | ||
const tokenNegotiatorClient = getOffChainConfigClient() | ||
let client = new Client({ | ||
type: 'active', | ||
issuers: tokenNegotiatorClient.getTokenStore().getCurrentIssuers(), | ||
options: {}, | ||
}) | ||
client.negotiate().then(() => { | ||
client.addTokenViaMagicLink('https://outlet-stage.brandconnector.io/#type=asn&ticket=MIGTME0MATYCAgTUAgECBEEEDoIoocY3CRCPqbHzou84M7C-cWAfzrTnPwz7qWGWv3UVn53jWeTG8CSykYVk-SUdNwlGTiD-h8Xsf2cGzniNPQNCAK6Q153BMkBc9E2AR3MjEWNU_f-15Cl2w0EIvaqGoqYrHKSMm3CIjKik_KBRTzRrbQqM5lGe_jUivjhmfwR5HOUc&secret=6191295225924896663249851881131284553005448461740837624904453538708620527945&id=bob%40alice.com') | ||
}); | ||
}) | ||
|
||
test('client can trigger promise to manage', () => { | ||
const tokenNegotiatorClient = getOffChainConfigClient() | ||
let client = new Client({ | ||
type: 'active', | ||
issuers: tokenNegotiatorClient.getTokenStore().getCurrentIssuers(), | ||
options: {}, | ||
}) | ||
client.negotiate().then(() => { | ||
client.handleWalletRequired([]); | ||
}); | ||
}) | ||
|
||
test('client can handle proof error', () => { | ||
const tokenNegotiatorClient = getOffChainConfigClient() | ||
let client = new Client({ | ||
type: 'active', | ||
issuers: tokenNegotiatorClient.getTokenStore().getCurrentIssuers(), | ||
options: {}, | ||
}) | ||
client.negotiate().then(() => { | ||
client.handleProofError({ error: 'something went wrong' }, 'devconVi'); | ||
}); | ||
}) | ||
|
||
test('tokenNegotiatorClient a failed new instance of client - missing issuers length', () => { | ||
let client = new Client({ | ||
type: 'passive', | ||
|
@@ -496,121 +510,3 @@ describe('client spec', () => { | |
}) | ||
|
||
}) | ||
|
||
// TODO: Reimplement cross-version test for version 3.1 | ||
/* describe('client spec cross-version', () => { | ||
let originalDocument = document | ||
let originalLocation = window.location | ||
const nonLocalUrl = 'https://non-local.url' | ||
beforeAll(() => { | ||
Object.defineProperty(global, 'document', { | ||
value: { | ||
location: { | ||
href: '', | ||
referrer: '', | ||
hash: '', | ||
search: '', | ||
origin: '', | ||
}, | ||
addEventListener: () => { | ||
return true | ||
}, | ||
}, | ||
}) | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
href: nonLocalUrl, | ||
origin: nonLocalUrl, | ||
}, | ||
writable: true, // possibility to override | ||
}) | ||
// required to force redirect mode | ||
window.navigator.brave = 1 | ||
}) | ||
afterAll(() => { | ||
Object.defineProperty(global, 'document', { | ||
value: originalDocument, | ||
}) | ||
Object.defineProperty(window, 'location', { | ||
value: originalLocation, | ||
}) | ||
}) | ||
test('Outlet_2_0 save magicLink', async () => { | ||
let magicLinkParams = | ||
'?ticket=MIGTME0MATYCAgFNAgEBBEEEF6_tKK2dCfLQiwS4FuqmiQDVrafJ05vCOkYN4iT28JULCClrvI2_kGTxrL12sXlH9w9mohLQlMdmaWvFzaZVlgNCAKu7SESOLf7L5sjZPcTQVkAu9YTC88mNK8oyUjiP2gsnTUxr0BGr0eWSTYmbDqNlX3JXOEqvEH39LEQjWsXn44oc&secret=45845870684&[email protected]' | ||
window.location.search = magicLinkParams | ||
// LocalStorage must be empty | ||
expect(localStorage.getItem(defaultConfig.itemStorageKey)).toBe(null) | ||
new outlet_2_0(tokenIssuer) | ||
expect(localStorage.getItem(defaultConfig.itemStorageKey)).toContain(magicLinkParams) | ||
}) | ||
test('Redirect Client_lastest -> Outlet 2.2', async () => { | ||
let client = new Client(config) | ||
// prepare Redirect URL | ||
await client.negotiate() | ||
let url = new URL(window.location.href) | ||
expect(new URLSearchParams(url.hash.substring(1)).get('action')).toBe('get-issuer-tokens') | ||
window.location.hash = url.hash | ||
new outlet_2_2(tokenIssuer) | ||
// need delay, because pageOnLoadEventHandler() is async | ||
await delay(1000) | ||
let hash = new URL(document.location.href).hash.substring(1) | ||
expect(new URLSearchParams(hash).get('action')).toBe('get-issuer-tokens-response') | ||
}) | ||
test('Redirect Client_2.2 -> Outlet_lastest', async () => { | ||
let client = new client_2_2(config) | ||
window.location.hash = '' | ||
window.location.href = 'http://localhost' | ||
document.location.hash = '' | ||
document.location.href = 'http://localhost' | ||
// prepare Redirect URL | ||
await client.negotiate() | ||
let url = new URL(document.location.href) | ||
expect(new URLSearchParams(url.hash.substring(1)).get('action')).toBe('get-issuer-tokens') | ||
// console.log( | ||
// `window.location.hash = "${window.location.hash}", | ||
// window.location.href = "${window.location.href}", | ||
// document.location.hash = "${document.location.hash}", | ||
// document.location.href = "${document.location.href}",` | ||
// ) | ||
window.location.hash = url.hash | ||
document.location.hash = url.hash | ||
document.referrer = nonLocalUrl | ||
localStorage.setItem('tn-whitelist', '{"https://non-local.url":{"type":"read"}}') | ||
new Outlet(tokenIssuer) | ||
// need delay, because pageOnLoadEventHandler() is async | ||
await delay(1000) | ||
let hash = new URL(window.location.href).hash.substring(1) | ||
expect(new URLSearchParams(hash).get('action')).toBe('get-issuer-tokens-response') | ||
}) | ||
test('tokenNegotiatorClient read prefixed param', async () => { | ||
window.location.hash = `p1=1&${URLNS}p2=2` | ||
let client = getOffChainConfigClient() | ||
expect(client.getDataFromQuery('p2')).toBe('2') | ||
expect(client.getDataFromQuery('p1')).toBe('1') | ||
}) | ||
})*/ |