Skip to content

Commit

Permalink
Merge pull request #48 from EOSIO/develop
Browse files Browse the repository at this point in the history
Develop Merge for Release
  • Loading branch information
Chris Allnutt authored Aug 1, 2019
2 parents 7515af1 + d84a60a commit 4efd7b9
Show file tree
Hide file tree
Showing 5 changed files with 1,383 additions and 1,582 deletions.
26 changes: 14 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ual-lynx",
"version": "0.1.1",
"version": "0.2.1",
"main": "dist/index.js",
"license": "MIT",
"author": {
Expand All @@ -23,10 +23,22 @@
"test": "jest"
},
"dependencies": {
"eos-lynx": "1.1.3",
"eosjs": "^20.0.0",
"universal-authenticator-library": "^0.1.0"
},
"devDependencies": {
"@babel/runtime": "^7.2.0",
"@blockone/tslint-config-blockone": "^1.0.0",
"@types/jest": "^24.0.15",
"jest": "^24.8.0",
"ts-jest": "^24.0.2",
"tslint": "^5.11.0",
"typescript": "^3.2.2",
"window": "^4.2.5"
},
"resolutions": {
"cache-base": "4.0.0"
},
"jest": {
"verbose": false,
"moduleFileExtensions": [
Expand All @@ -47,15 +59,5 @@
],
"testRegex": "(/src/.*(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"testEnvironment": "jsdom"
},
"devDependencies": {
"@babel/runtime": "^7.2.0",
"@blockone/tslint-config-blockone": "^1.0.0",
"@types/jest": "^23.3.10",
"jest": "^23.6.0",
"ts-jest": "^23.10.5",
"tslint": "^5.11.0",
"typescript": "^3.2.2",
"window": "^4.2.5"
}
}
11 changes: 11 additions & 0 deletions src/Lynx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('Lynx', () => {
let lynxMobile: any
const lynxIosBrowser: string = 'EOSLynx IOS'
const lynxAndroidBrowser: string = 'EOSLynx Android'
const lynxDesktopBrowser: string = 'EOSLynx Desktop'
const otherBrowser: string = 'Chrome'

beforeEach(() => {
Expand Down Expand Up @@ -125,6 +126,16 @@ describe('Lynx', () => {
jest.runAllTimers()
expect(shouldRender).toBe(true)
})

it('should return true if all given chains are supported within lynx desktop browser', () => {
window.lynxMobile = lynxMobile
window.navigator.userAgent = lynxDesktopBrowser
const chains = supportedChains
const lynx = new Lynx(chains)
const shouldRender = lynx.shouldRender()
jest.runAllTimers()
expect(shouldRender).toBe(true)
})
})

describe('login', () => {
Expand Down
56 changes: 35 additions & 21 deletions src/LynxUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,56 +57,69 @@ describe('LynxUser', () => {
})

describe('signArbitrary', () => {
it('throws UALError if not iOS', async () => {
const requestArbitrarySignature = jest.fn()

it('throws UALError on api error', async () => {
const errorMsg = 'Error signing arbitrary data'
const requestArbitrarySignature = jest
.fn()
.mockImplementation(() => {
throw new Error(errorMsg)
})
window.lynxMobile = {
requestArbitrarySignature
}
window.navigator.userAgent = 'EOSLynx Android'
window.navigator.userAgent = 'EOSLynx IOS'
let didThrow = true

try {
await user.signArbitrary('myPublicKey', 'This should be signed', 'Some help text')
didThrow = false
} catch (e) {
const ex = e as UALLynxError
expect(ex.message).toEqual('Arbitrary data signing is only support on iOS')
expect(ex.message).toEqual('Unable to sign arbitrary string')
expect(ex.source).toEqual(Name)
expect(ex.type).toEqual(UALErrorType.Signing)
expect(ex.cause).toBeNull()
expect(ex.cause).toEqual(new Error(errorMsg))
}

expect(didThrow).toBe(true)
})

it('throws UALError on api error', async () => {
const errorMsg = 'Error signing arbitrary data'
it('signs arbitrary data in IOS Browser', async () => {
const expectedSignature = 'sig1234567890'
const requestArbitrarySignature = jest
.fn()
.mockImplementation(() => {
throw new Error(errorMsg)
return expectedSignature
})
window.lynxMobile = {
requestArbitrarySignature
}
window.navigator.userAgent = 'EOSLynx IOS'
let didThrow = true

try {
await user.signArbitrary('myPublicKey', 'This should be signed', 'Some help text')
didThrow = false
} catch (e) {
const ex = e as UALLynxError
expect(ex.message).toEqual('Unable to sign arbitrary string')
expect(ex.source).toEqual(Name)
expect(ex.type).toEqual(UALErrorType.Signing)
expect(ex.cause).toEqual(new Error(errorMsg))
const signature = await user.signArbitrary('myPublicKey', 'This should be signed', 'Some help text')

expect(signature).toEqual(expectedSignature)
})

it('signs arbitrary data in Android Browser', async () => {
const expectedSignature = 'sig1234567890'
const requestArbitrarySignature = jest
.fn()
.mockImplementation(() => {
return expectedSignature
})
window.lynxMobile = {
requestArbitrarySignature
}
window.navigator.userAgent = 'EOSLynx Android'

expect(didThrow).toBe(true)
const signature = await user.signArbitrary('myPublicKey', 'This should be signed', 'Some help text')

expect(signature).toEqual(expectedSignature)
})

it('signs arbitrary data', async () => {
it('signs arbitrary data in Desktop Browser', async () => {
const expectedSignature = 'sig1234567890'
const requestArbitrarySignature = jest
.fn()
Expand All @@ -116,12 +129,13 @@ describe('LynxUser', () => {
window.lynxMobile = {
requestArbitrarySignature
}
window.navigator.userAgent = 'EOSLynx IOS'
window.navigator.userAgent = 'EOSLynx Desktop'

const signature = await user.signArbitrary('myPublicKey', 'This should be signed', 'Some help text')

expect(signature).toEqual(expectedSignature)
})

})

describe('signTransaction', () => {
Expand Down
22 changes: 5 additions & 17 deletions src/LynxUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,13 @@ export class LynxUser extends User {
}

public async signArbitrary(_: string, data: string, helpText: string): Promise<string> {
if (this.isIOS()) {
try {
return window.lynxMobile.requestArbitrarySignature({data, whatFor: helpText})
} catch (e) {
throw new UALLynxError(
'Unable to sign arbitrary string',
UALErrorType.Signing,
e
)
}
} else {
try {
return window.lynxMobile.requestArbitrarySignature({data, whatFor: helpText})
} catch (e) {
throw new UALLynxError(
'Arbitrary data signing is only support on iOS',
'Unable to sign arbitrary string',
UALErrorType.Signing,
null
e
)
}
}
Expand Down Expand Up @@ -95,8 +87,4 @@ export class LynxUser extends User {
return this.keys
}

private isIOS(): boolean {
const userAgent = window.navigator.userAgent
return userAgent === 'EOSLynx IOS'
}
}
Loading

0 comments on commit 4efd7b9

Please sign in to comment.