Skip to content

Commit

Permalink
Merge pull request #77 from WalletConnect/beta.6
Browse files Browse the repository at this point in the history
beta.6
  • Loading branch information
pedrouid authored Mar 3, 2019
2 parents f8c1e6f + a4ca4a1 commit 3f73853
Show file tree
Hide file tree
Showing 19 changed files with 1,001 additions and 910 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0-beta.5",
"version": "1.0.0-beta.6",
"packages": [
"packages/*"
]
Expand Down
244 changes: 122 additions & 122 deletions packages/browser/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@walletconnect/browser",
"version": "1.0.0-beta.5",
"version": "1.0.0-beta.6",
"description": "Browser SDK for WalletConnect",
"scripts": {
"clean": "rm -rf lib",
Expand Down Expand Up @@ -54,9 +54,9 @@
"webpack-cli": "^3.2.1"
},
"dependencies": {
"@walletconnect/core": "^1.0.0-beta.5",
"@walletconnect/types": "^1.0.0-beta.5",
"@walletconnect/utils": "^1.0.0-beta.5"
"@walletconnect/core": "^1.0.0-beta.6",
"@walletconnect/types": "^1.0.0-beta.6",
"@walletconnect/utils": "^1.0.0-beta.6"
},
"gitHead": "165f7993c2acc907c653c02847fb02721052c6e7"
}
244 changes: 122 additions & 122 deletions packages/core/package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@walletconnect/core",
"version": "1.0.0-beta.5",
"version": "1.0.0-beta.6",
"description": "Core Library for WalletConnect",
"scripts": {
"clean": "rm -rf lib",
Expand Down Expand Up @@ -53,8 +53,8 @@
"webpack-cli": "^3.2.1"
},
"dependencies": {
"@walletconnect/types": "^1.0.0-beta.5",
"@walletconnect/utils": "^1.0.0-beta.5"
"@walletconnect/types": "^1.0.0-beta.6",
"@walletconnect/utils": "^1.0.0-beta.6"
},
"gitHead": "165f7993c2acc907c653c02847fb02721052c6e7"
}
64 changes: 56 additions & 8 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import {
payloadId,
uuid,
formatRpcError,
parseWalletConnectUri
parseWalletConnectUri,
isHexStrict,
convertUtf8ToHex
} from '@walletconnect/utils'

// -- typeChecks ----------------------------------------------------------- //
Expand Down Expand Up @@ -121,6 +123,14 @@ class Connector {
this._browser = browser
this._pingInterval = null

if (
browser &&
window.location.protocol !== 'https:' &&
window.location.hostname !== 'localhost'
) {
throw new Error('HTTPS is required for non-localhost origins')
}

if (clientMeta) {
this.clientMeta = clientMeta
}
Expand Down Expand Up @@ -363,7 +373,7 @@ class Connector {
this._eventEmitters.push(eventEmitter)
}

public async createSession (): Promise<void> {
public async createSession (opts?: { chainId: number }): Promise<void> {
if (this._connected) {
throw new Error('Session currently connected')
}
Expand All @@ -379,7 +389,8 @@ class Connector {
params: [
{
peerId: this.clientId,
peerMeta: this.clientMeta
peerMeta: this.clientMeta,
chainId: opts && opts.chainId ? opts.chainId : null
}
]
})
Expand All @@ -392,7 +403,6 @@ class Connector {
'Session update rejected',
this.handshakeTopic
)
this._setStorageSession()
}

public approveSession (sessionStatus: ISessionStatus) {
Expand Down Expand Up @@ -429,7 +439,11 @@ class Connector {
}
]
})
this._setStorageSession()
if (this._connected) {
this._setStorageSession()
} else {
this._removeStorageSession()
}
}

public rejectSession (sessionError?: ISessionError) {
Expand Down Expand Up @@ -487,7 +501,11 @@ class Connector {
}
]
})
this._setStorageSession()
if (this._connected) {
this._setStorageSession()
} else {
this._removeStorageSession()
}
}

public killSession (sessionError?: ISessionError) {
Expand Down Expand Up @@ -545,6 +563,28 @@ class Connector {
}
}

public async signPersonalMessage (params: any[]) {
if (!this._connected) {
throw new Error('Session currently disconnected')
}

if (!isHexStrict(params[1])) {
params[1] = convertUtf8ToHex(params[1])
}

const request = this._formatRequest({
method: 'personal_sign',
params
})

try {
const result = await this._sendCallRequest(request)
return result
} catch (error) {
throw error
}
}

public async signTypedData (params: any[]) {
if (!this._connected) {
throw new Error('Session currently disconnected')
Expand Down Expand Up @@ -748,7 +788,11 @@ class Connector {
]
})
}
this._setStorageSession()
if (this._connected) {
this._setStorageSession()
} else {
this._removeStorageSession()
}
} else {
this._handleSessionDisconnect(errorMsg)
}
Expand Down Expand Up @@ -908,7 +952,11 @@ class Connector {
private _swapKey () {
this._key = this._nextKey
this._nextKey = null
this._setStorageSession()
if (this._connected) {
this._setStorageSession()
} else {
this._removeStorageSession()
}
}

// -- websocket ------------------------------------------------------- //
Expand Down
Loading

0 comments on commit 3f73853

Please sign in to comment.