@hashgraph/hedera-wallet-connect 0.1.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
- package/.github/ISSUE_TEMPLATE/hip_820.md +16 -0
- package/.github/dependabot.yml +17 -0
- package/.github/workflows/prettier.yml +28 -0
- package/.github/workflows/publish.yml +35 -0
- package/.github/workflows/test.yml +32 -0
- package/.husky/pre-commit +4 -0
- package/.lintstagedrc.json +5 -0
- package/.prettierignore +3 -0
- package/LICENSE +201 -21
- package/README.md +132 -107
- package/dist/browser-cjs-metafile.json +1 -0
- package/dist/browser-cjs.js +240 -0
- package/dist/browser-esm-metafile.json +1 -0
- package/dist/browser-esm.js +240 -0
- package/dist/node-cjs-metafile.json +1 -0
- package/dist/node-cjs.js +11391 -0
- package/dist/node-esm-metafile.json +1 -0
- package/dist/node-esm.js +11391 -0
- package/jest.config.ts +33 -0
- package/package.json +59 -31
- package/scripts/examples/build.mjs +54 -0
- package/scripts/examples/dev.mjs +54 -0
- package/scripts/lib/build.mjs +40 -0
- package/scripts/lib/context.mjs +71 -0
- package/scripts/lib/watch.mjs +28 -0
- package/typedoc.json +10 -0
- package/.editorconfig +0 -19
- package/.github/workflows/npm-publish.yml +0 -18
- package/lib/esm/Connector.js +0 -81
- package/lib/esm/Connector.js.map +0 -1
- package/lib/esm/DAppConnector.js +0 -118
- package/lib/esm/DAppConnector.js.map +0 -1
- package/lib/esm/ErrorHelper.js +0 -97
- package/lib/esm/ErrorHelper.js.map +0 -1
- package/lib/esm/Utils.js +0 -99
- package/lib/esm/Utils.js.map +0 -1
- package/lib/esm/WCSigner.js +0 -241
- package/lib/esm/WCSigner.js.map +0 -1
- package/lib/esm/WalletConnector.js +0 -203
- package/lib/esm/WalletConnector.js.map +0 -1
- package/lib/esm/index.js +0 -4
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/types/Connector.d.ts +0 -18
- package/lib/esm/types/Connector.d.ts.map +0 -1
- package/lib/esm/types/DAppConnector.d.ts +0 -27
- package/lib/esm/types/DAppConnector.d.ts.map +0 -1
- package/lib/esm/types/ErrorHelper.d.ts +0 -15
- package/lib/esm/types/ErrorHelper.d.ts.map +0 -1
- package/lib/esm/types/Utils.d.ts +0 -39
- package/lib/esm/types/Utils.d.ts.map +0 -1
- package/lib/esm/types/WCSigner.d.ts +0 -33
- package/lib/esm/types/WCSigner.d.ts.map +0 -1
- package/lib/esm/types/WalletConnector.d.ts +0 -21
- package/lib/esm/types/WalletConnector.d.ts.map +0 -1
- package/lib/esm/types/index.d.ts +0 -4
- package/lib/esm/types/index.d.ts.map +0 -1
package/jest.config.ts
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Hedera Wallet Connect
|
4
|
+
*
|
5
|
+
* Copyright (C) 2023 Hedera Hashgraph, LLC
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
|
21
|
+
import type { Config } from 'jest'
|
22
|
+
|
23
|
+
const config: Config = {
|
24
|
+
preset: 'ts-jest/presets/js-with-ts',
|
25
|
+
detectOpenHandles: true,
|
26
|
+
fakeTimers: {
|
27
|
+
enableGlobally: true,
|
28
|
+
},
|
29
|
+
testMatch: ['**/?(*.)+(spec|test).ts?(x)', '!**/DAppConnector.test.ts', '!**/wallet*/**'],
|
30
|
+
transformIgnorePatterns: ['node_modules/(?!@walletconnect)'],
|
31
|
+
}
|
32
|
+
|
33
|
+
export default config
|
package/package.json
CHANGED
@@ -1,41 +1,69 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hashgraph/hedera-wallet-connect",
|
3
|
-
"version": "
|
4
|
-
"
|
5
|
-
"exports": {
|
6
|
-
".": {
|
7
|
-
"types": "./lib/esm/types/index.d.ts",
|
8
|
-
"import": "./lib/esm/index.js"
|
9
|
-
}
|
10
|
-
},
|
11
|
-
"types": "./lib/esm/types/index.d.ts",
|
12
|
-
"main": "./lib/esm/index.js",
|
13
|
-
"author": "Blade Labs",
|
14
|
-
"license": "MIT",
|
3
|
+
"version": "1.0.2",
|
4
|
+
"description": "A library to facilitate integrating Hedera with WalletConnect",
|
15
5
|
"repository": {
|
16
6
|
"type": "git",
|
17
|
-
"url": "https://github.com/hashgraph/hedera-wallet-connect"
|
7
|
+
"url": "git+https://github.com/hashgraph/hedera-wallet-connect.git"
|
18
8
|
},
|
19
|
-
"
|
20
|
-
|
21
|
-
|
22
|
-
"
|
23
|
-
"
|
9
|
+
"main": "./dist/node-cjs.js",
|
10
|
+
"module": "./dist/node-esm.js",
|
11
|
+
"browser": {
|
12
|
+
"./dist/node-cjs.js": "./dist/browser-cjs.js",
|
13
|
+
"./dist/node-esm.js": "./dist/browser-esm.js"
|
14
|
+
},
|
15
|
+
"types": "./dist/types/index.d.ts",
|
16
|
+
"author": "Hgraph <support@hgraph.io>",
|
17
|
+
"keywords": [
|
18
|
+
"hedera",
|
19
|
+
"walletconnect",
|
20
|
+
"hashgraph"
|
21
|
+
],
|
22
|
+
"license": "Apache-2.0",
|
23
|
+
"devDependencies": {
|
24
|
+
"@types/jest": "^29.5.3",
|
25
|
+
"@types/node": "^20.11.6",
|
26
|
+
"@walletconnect/modal": "^2.6.2",
|
27
|
+
"@walletconnect/sign-client": "^2.11.0",
|
28
|
+
"@walletconnect/types": "^2.11.0",
|
29
|
+
"concurrently": "^8.2.2",
|
30
|
+
"esbuild": "^0.19.12",
|
31
|
+
"esbuild-plugin-copy": "^2.1.1",
|
32
|
+
"eslint-plugin-tsdoc": "^0.2.17",
|
33
|
+
"husky": "^8.0.0",
|
34
|
+
"jest": "^29.7.0",
|
35
|
+
"lint-staged": "^15.1.0",
|
36
|
+
"lokijs": "^1.5.12",
|
37
|
+
"nodemon": "^3.0.3",
|
38
|
+
"prettier": "^3.2.4",
|
39
|
+
"rimraf": "^5.0.5",
|
40
|
+
"ts-jest": "^29.1.2",
|
41
|
+
"ts-node": "^10.9.2",
|
42
|
+
"typedoc": "^0.25.7",
|
43
|
+
"typedoc-theme-hierarchy": "^4.1.2",
|
44
|
+
"typescript": "^5.2.2"
|
24
45
|
},
|
25
46
|
"dependencies": {
|
26
|
-
"@
|
27
|
-
"@hashgraph/
|
28
|
-
"@walletconnect/
|
29
|
-
"@walletconnect/types": "^2.
|
30
|
-
"@walletconnect/
|
31
|
-
"@walletconnect/
|
32
|
-
"buffer": "^6.0.3",
|
33
|
-
"events": "^3.3.0",
|
34
|
-
"rxjs": "^7.5.7"
|
47
|
+
"@hashgraph/sdk": "^2.40.0",
|
48
|
+
"@hashgraph/walletconnect": "file:./",
|
49
|
+
"@walletconnect/qrcode-modal": "^1.8.0",
|
50
|
+
"@walletconnect/types": "^2.11.0",
|
51
|
+
"@walletconnect/utils": "^2.11.0",
|
52
|
+
"@walletconnect/web3wallet": "^1.9.3"
|
35
53
|
},
|
36
|
-
"
|
37
|
-
"
|
38
|
-
"
|
39
|
-
"
|
54
|
+
"scripts": {
|
55
|
+
"build": "npm run build:types && node scripts/lib/build.mjs",
|
56
|
+
"build:types": "tsc --emitDeclarationOnly --declaration --declarationMap --outDir dist/types",
|
57
|
+
"build:example": "node scripts/examples/build.mjs",
|
58
|
+
"build:docs": "typedoc --options typedoc.json",
|
59
|
+
"watch": "nodemon --watch src/lib/ --ext ts --exec \"npm run build\"",
|
60
|
+
"dev": "rimraf dist && npm run build && concurrently --raw \"npm run watch\" \"node scripts/examples/dev.mjs\"",
|
61
|
+
"test": "jest",
|
62
|
+
"test:connect": "jest --testMatch '**/DAppConnector.test.ts' --verbose",
|
63
|
+
"prepublishOnly": "rm -Rf dist && npm run build",
|
64
|
+
"prepare": "husky install",
|
65
|
+
"prettier:check": "prettier --check ./src/",
|
66
|
+
"prettier:fix": "prettier --write ./src/",
|
67
|
+
"test:sigMap": "jest --testMatch '**/SignatureMapHelpers.test.ts' --verbose"
|
40
68
|
}
|
41
69
|
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Hedera Wallet Connect
|
4
|
+
*
|
5
|
+
* Copyright (C) 2023 Hedera Hashgraph, LLC
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
|
21
|
+
import * as esbuild from 'esbuild'
|
22
|
+
import copy from 'esbuild-plugin-copy'
|
23
|
+
|
24
|
+
export const config = {
|
25
|
+
bundle: true,
|
26
|
+
minify: false,
|
27
|
+
platform: 'browser',
|
28
|
+
// format: 'esm',
|
29
|
+
alias: {
|
30
|
+
'@hashgraph/sdk': './node_modules/@hashgraph/sdk/src/index.js',
|
31
|
+
'@hashgraph/proto': './node_modules/@hashgraph/proto',
|
32
|
+
},
|
33
|
+
plugins: [
|
34
|
+
copy({
|
35
|
+
assets: {
|
36
|
+
from: ['src/examples/typescript/**/*.(html|css|ico|jpg|png)'],
|
37
|
+
to: ['./'],
|
38
|
+
},
|
39
|
+
watch: true, // for ../dev.mjs
|
40
|
+
}),
|
41
|
+
],
|
42
|
+
outdir: 'dist/examples/typescript',
|
43
|
+
entryPoints: [
|
44
|
+
'src/examples/typescript/main.ts',
|
45
|
+
'src/examples/typescript/dapp/main.ts',
|
46
|
+
'src/examples/typescript/wallet/main.ts',
|
47
|
+
],
|
48
|
+
define: {
|
49
|
+
'process.env.dappUrl': '"https://wc.hgraph.app/dapp/index.html"',
|
50
|
+
'process.env.walletUrl': '"https://wallet.wc.hgraph.app/wallet/index.html"',
|
51
|
+
},
|
52
|
+
}
|
53
|
+
|
54
|
+
esbuild.build(config)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Hedera Wallet Connect
|
4
|
+
*
|
5
|
+
* Copyright (C) 2023 Hedera Hashgraph, LLC
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
|
21
|
+
import * as esbuild from 'esbuild'
|
22
|
+
import { config } from './build.mjs'
|
23
|
+
|
24
|
+
const devConfig = {
|
25
|
+
...config,
|
26
|
+
define: {
|
27
|
+
'process.env.dappUrl': '"http://localhost:8080/dapp/index.html"',
|
28
|
+
'process.env.walletUrl': '"http://localhost:8081/wallet/index.html"',
|
29
|
+
},
|
30
|
+
}
|
31
|
+
|
32
|
+
let ctx8080 = await esbuild.context(devConfig)
|
33
|
+
let ctx8081 = await esbuild.context(devConfig)
|
34
|
+
|
35
|
+
/*
|
36
|
+
* watches for file changes and serves most recent files
|
37
|
+
*/
|
38
|
+
async function main() {
|
39
|
+
const server1 = await ctx8080.serve({
|
40
|
+
servedir: 'dist/examples/typescript',
|
41
|
+
host: 'localhost',
|
42
|
+
port: 8080,
|
43
|
+
})
|
44
|
+
const server2 = await ctx8081.serve({
|
45
|
+
servedir: 'dist/examples/typescript',
|
46
|
+
host: 'localhost',
|
47
|
+
port: 8081,
|
48
|
+
})
|
49
|
+
|
50
|
+
console.log(`Server 1 is up ${server1.host}:${server1.port}`)
|
51
|
+
console.log(`Server 2 is up ${server2.host}:${server2.port}`)
|
52
|
+
}
|
53
|
+
|
54
|
+
await main()
|
@@ -0,0 +1,40 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Hedera Wallet Connect
|
4
|
+
*
|
5
|
+
* Copyright (C) 2023 Hedera Hashgraph, LLC
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
|
21
|
+
import fs from 'node:fs'
|
22
|
+
import * as esbuild from 'esbuild'
|
23
|
+
import * as ctx from './context.mjs'
|
24
|
+
|
25
|
+
/*
|
26
|
+
* https://esbuild.github.io/analyze/
|
27
|
+
* - metafiles.json files are generated by this script to analyze the build
|
28
|
+
*/
|
29
|
+
esbuild.build(ctx.nodeCjs).then((result) => {
|
30
|
+
fs.writeFileSync('dist/node-cjs-metafile.json', JSON.stringify(result.metafile))
|
31
|
+
})
|
32
|
+
esbuild.build(ctx.nodeEsm).then((result) => {
|
33
|
+
fs.writeFileSync('dist/node-esm-metafile.json', JSON.stringify(result.metafile))
|
34
|
+
})
|
35
|
+
esbuild.build(ctx.browserCjs).then((result) => {
|
36
|
+
fs.writeFileSync('dist/browser-cjs-metafile.json', JSON.stringify(result.metafile))
|
37
|
+
})
|
38
|
+
esbuild.build(ctx.browserEsm).then((result) => {
|
39
|
+
fs.writeFileSync('dist/browser-esm-metafile.json', JSON.stringify(result.metafile))
|
40
|
+
})
|
@@ -0,0 +1,71 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Hedera Wallet Connect
|
4
|
+
*
|
5
|
+
* Copyright (C) 2023 Hedera Hashgraph, LLC
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
|
21
|
+
import * as esbuild from 'esbuild'
|
22
|
+
|
23
|
+
// https://esbuild.github.io/api/#main-fields-for-package-authors
|
24
|
+
export const common = {
|
25
|
+
entryPoints: ['src/index.ts'],
|
26
|
+
bundle: true,
|
27
|
+
minify: true,
|
28
|
+
metafile: true,
|
29
|
+
loader: {
|
30
|
+
'.json': 'text',
|
31
|
+
},
|
32
|
+
// exports field in @hashgraph/sdk overwrites browser field
|
33
|
+
// https://github.com/evanw/esbuild/issues/1275
|
34
|
+
alias: {
|
35
|
+
'@hashgraph/sdk': './node_modules/@hashgraph/sdk/src/index.js',
|
36
|
+
'@hashgraph/proto': './node_modules/@hashgraph/proto',
|
37
|
+
},
|
38
|
+
// external: ['./node_modules/@hashgraph/sdk/src/index.js'],
|
39
|
+
}
|
40
|
+
|
41
|
+
export const nodeCjs = {
|
42
|
+
...common,
|
43
|
+
format: 'cjs',
|
44
|
+
platform: 'node',
|
45
|
+
target: ['node18'],
|
46
|
+
outfile: 'dist/node-cjs.js',
|
47
|
+
}
|
48
|
+
|
49
|
+
export const nodeEsm = {
|
50
|
+
...common,
|
51
|
+
format: 'esm',
|
52
|
+
platform: 'node',
|
53
|
+
target: ['node18'],
|
54
|
+
outfile: 'dist/node-esm.js',
|
55
|
+
}
|
56
|
+
|
57
|
+
export const browserEsm = {
|
58
|
+
...common,
|
59
|
+
format: 'esm',
|
60
|
+
platform: 'browser',
|
61
|
+
target: ['chrome58', 'firefox57', 'safari11', 'edge88'],
|
62
|
+
outfile: 'dist/browser-esm.js',
|
63
|
+
}
|
64
|
+
|
65
|
+
export const browserCjs = {
|
66
|
+
...common,
|
67
|
+
format: 'cjs',
|
68
|
+
platform: 'browser',
|
69
|
+
target: ['chrome58', 'firefox57', 'safari11', 'edge88'],
|
70
|
+
outfile: 'dist/browser-cjs.js',
|
71
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Hedera Wallet Connect
|
4
|
+
*
|
5
|
+
* Copyright (C) 2023 Hedera Hashgraph, LLC
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
|
21
|
+
import * as context from './context.mjs'
|
22
|
+
|
23
|
+
await Promise.all([
|
24
|
+
context.nodeCjs.watch(),
|
25
|
+
context.nodeEsm.watch(),
|
26
|
+
context.browserEsm.watch(),
|
27
|
+
context.browserCjs.watch(),
|
28
|
+
])
|
package/typedoc.json
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "https://typedoc.org/schema.json",
|
3
|
+
"entryPointStrategy": "expand",
|
4
|
+
"entryPoints": ["./src/lib"],
|
5
|
+
"plugin": ["typedoc-theme-hierarchy"],
|
6
|
+
"theme": "hierarchy",
|
7
|
+
"out": "dist/examples/typescript/docs",
|
8
|
+
"sourceLinkExternal": true,
|
9
|
+
"basePath": "./docs"
|
10
|
+
}
|
package/.editorconfig
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
root = true
|
2
|
-
|
3
|
-
[*]
|
4
|
-
charset = utf-8
|
5
|
-
end_of_line = lf
|
6
|
-
indent_size = 4
|
7
|
-
indent_style = space
|
8
|
-
insert_final_newline = true
|
9
|
-
max_line_length = 120
|
10
|
-
tab_width = 4
|
11
|
-
|
12
|
-
[{*.ts, *js}]
|
13
|
-
indent_size = 2
|
14
|
-
|
15
|
-
[{*.json,jest.config}]
|
16
|
-
indent_size = 2
|
17
|
-
|
18
|
-
[{*.yaml,*.yml}]
|
19
|
-
indent_size = 2
|
@@ -1,18 +0,0 @@
|
|
1
|
-
name: Publish to NPM
|
2
|
-
on:
|
3
|
-
release:
|
4
|
-
types: [published]
|
5
|
-
jobs:
|
6
|
-
build:
|
7
|
-
runs-on: ubuntu-latest
|
8
|
-
steps:
|
9
|
-
- uses: actions/checkout@v3
|
10
|
-
# Setup .npmrc file to publish to npm
|
11
|
-
- uses: actions/setup-node@v3
|
12
|
-
with:
|
13
|
-
node-version: '18.x'
|
14
|
-
registry-url: 'https://registry.npmjs.org'
|
15
|
-
- run: npm ci
|
16
|
-
- run: npm publish --access=public
|
17
|
-
env:
|
18
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/lib/esm/Connector.js
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
import { catchError, from, timeout } from "rxjs";
|
2
|
-
import { getAppMetadata, getSdkError } from "@walletconnect/utils";
|
3
|
-
export class Connector {
|
4
|
-
dAppMetadata;
|
5
|
-
isInitializing = false;
|
6
|
-
client = null;
|
7
|
-
session = null;
|
8
|
-
signers = [];
|
9
|
-
constructor(metadata) {
|
10
|
-
this.dAppMetadata = metadata || getAppMetadata();
|
11
|
-
}
|
12
|
-
async checkPersistedState() {
|
13
|
-
if (!this.client) {
|
14
|
-
throw new Error("WC is not initialized");
|
15
|
-
}
|
16
|
-
if (this.session) {
|
17
|
-
return this.session;
|
18
|
-
}
|
19
|
-
if (this.client.session.length) {
|
20
|
-
const sessionCheckPromises = this.client.session
|
21
|
-
.getAll()
|
22
|
-
.map((session) => {
|
23
|
-
if (session.expiry * 1000 <= Date.now()) {
|
24
|
-
try {
|
25
|
-
this.client.disconnect({
|
26
|
-
topic: session.topic,
|
27
|
-
reason: { code: 0, message: "Session expired" }
|
28
|
-
});
|
29
|
-
}
|
30
|
-
catch (e) {
|
31
|
-
console.log("Non existing session with topic:", session.topic);
|
32
|
-
}
|
33
|
-
return Promise.reject("Session expired");
|
34
|
-
}
|
35
|
-
return new Promise((resolve, reject) => from(this.client.ping({ topic: session.topic }))
|
36
|
-
.pipe(timeout(3000), catchError(async (err) => {
|
37
|
-
try {
|
38
|
-
await this.client.disconnect({
|
39
|
-
topic: session.topic,
|
40
|
-
reason: { code: 0, message: "Ping was unsuccessful" }
|
41
|
-
});
|
42
|
-
}
|
43
|
-
catch (e) {
|
44
|
-
console.log("Non existing session with topic:", session.topic);
|
45
|
-
}
|
46
|
-
reject("Non existing session");
|
47
|
-
})).subscribe(() => {
|
48
|
-
resolve(session);
|
49
|
-
}));
|
50
|
-
});
|
51
|
-
this.session = await Promise.any(sessionCheckPromises).catch(() => null);
|
52
|
-
return this.session;
|
53
|
-
}
|
54
|
-
this.session = null;
|
55
|
-
return this.session;
|
56
|
-
}
|
57
|
-
async disconnect() {
|
58
|
-
if (!this.client) {
|
59
|
-
throw new Error("WC is not initialized");
|
60
|
-
}
|
61
|
-
try {
|
62
|
-
if (this.session) {
|
63
|
-
await this.client.disconnect({
|
64
|
-
topic: this.session.topic,
|
65
|
-
reason: getSdkError("USER_DISCONNECTED")
|
66
|
-
});
|
67
|
-
}
|
68
|
-
}
|
69
|
-
finally {
|
70
|
-
this.reset();
|
71
|
-
}
|
72
|
-
}
|
73
|
-
reset() {
|
74
|
-
this.session = null;
|
75
|
-
this.signers = [];
|
76
|
-
}
|
77
|
-
get initialized() {
|
78
|
-
return Boolean(this.client && !this.isInitializing);
|
79
|
-
}
|
80
|
-
}
|
81
|
-
//# sourceMappingURL=Connector.js.map
|
package/lib/esm/Connector.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"Connector.js","sourceRoot":"","sources":["../../src/Connector.ts"],"names":[],"mappings":"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","sourcesContent":["import SignClient from \"@walletconnect/sign-client\";\nimport {catchError, from, timeout} from \"rxjs\";\nimport {Signer} from \"@hashgraph/sdk\";\nimport {SessionTypes, SignClientTypes} from \"@walletconnect/types\";\nimport {getAppMetadata, getSdkError} from \"@walletconnect/utils\";\n\ndeclare type Client = SignClient.default;\n\nexport class Connector {\n protected readonly dAppMetadata: SignClientTypes.Metadata;\n protected isInitializing: boolean = false;\n protected client: Client | null = null;\n protected session: SessionTypes.Struct | null = null;\n protected signers: Signer[] = [];\n\n protected constructor(metadata?: SignClientTypes.Metadata) {\n this.dAppMetadata = metadata || getAppMetadata();\n }\n\n async checkPersistedState() {\n if (!this.client) {\n throw new Error(\"WC is not initialized\");\n }\n\n if (this.session) {\n return this.session;\n }\n\n if (this.client.session.length) {\n const sessionCheckPromises: Promise<SessionTypes.Struct | null>[] = this.client.session\n .getAll()\n .map((session: SessionTypes.Struct) => {\n if (session.expiry * 1000 <= Date.now()) {\n try {\n this.client!.disconnect({\n topic: session.topic,\n reason: { code: 0, message: \"Session expired\" }\n });\n } catch (e) {\n console.log(\"Non existing session with topic:\", session.topic)\n }\n return Promise.reject(\"Session expired\");\n }\n return new Promise((resolve, reject) =>\n from(this.client!.ping({ topic: session.topic }))\n .pipe(\n timeout(3000),\n catchError(async (err) => {\n try {\n await this.client!.disconnect({\n topic: session.topic,\n reason: { code: 0, message: \"Ping was unsuccessful\" }\n });\n } catch (e) {\n console.log(\"Non existing session with topic:\", session.topic)\n }\n reject(\"Non existing session\");\n })\n ).subscribe(() => {\n resolve(session);\n })\n );\n });\n this.session = await Promise.any(sessionCheckPromises).catch(() => null);\n return this.session;\n }\n\n this.session = null;\n return this.session;\n }\n\n\n async disconnect() {\n if (!this.client) {\n throw new Error(\"WC is not initialized\");\n }\n try {\n if (this.session) {\n await this.client.disconnect({\n topic: this.session.topic,\n reason: getSdkError(\"USER_DISCONNECTED\")\n });\n }\n } finally {\n this.reset();\n }\n }\n\n private reset() {\n this.session = null;\n this.signers = [];\n }\n\n get initialized(): boolean {\n return Boolean(this.client && !this.isInitializing);\n }\n}\n"]}
|
package/lib/esm/DAppConnector.js
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
import { AccountId, LedgerId } from "@hashgraph/sdk";
|
2
|
-
import QRCodeModal from "@walletconnect/qrcode-modal";
|
3
|
-
import { SignClient } from "@walletconnect/sign-client";
|
4
|
-
import { Subject } from "rxjs";
|
5
|
-
import { Connector } from "./Connector.js";
|
6
|
-
import { getAccountLedgerPairsFromSession, getExtensionMethodsFromSession, getLedgerIDsFromSession, getRequiredNamespaces } from "./Utils.js";
|
7
|
-
import { WCSigner } from "./WCSigner.js";
|
8
|
-
import { HWCError } from "./ErrorHelper.js";
|
9
|
-
export class DAppConnector extends Connector {
|
10
|
-
allowedEvents = [];
|
11
|
-
extensionMethods = [];
|
12
|
-
static instance;
|
13
|
-
$events = new Subject();
|
14
|
-
constructor(metadata) {
|
15
|
-
super(metadata);
|
16
|
-
DAppConnector.instance = this;
|
17
|
-
}
|
18
|
-
async init(events = [], methods = []) {
|
19
|
-
this.allowedEvents = events;
|
20
|
-
this.extensionMethods = methods;
|
21
|
-
try {
|
22
|
-
this.isInitializing = true;
|
23
|
-
this.client = await SignClient.init({
|
24
|
-
relayUrl: "wss://relay.walletconnect.com",
|
25
|
-
projectId: "ce06497abf4102004138a10edd29c921",
|
26
|
-
metadata: this.dAppMetadata
|
27
|
-
});
|
28
|
-
this.subscribeToEvents();
|
29
|
-
const existingSession = await this.checkPersistedState();
|
30
|
-
if (existingSession) {
|
31
|
-
await this.onSessionConnected(existingSession);
|
32
|
-
}
|
33
|
-
}
|
34
|
-
finally {
|
35
|
-
this.isInitializing = false;
|
36
|
-
}
|
37
|
-
}
|
38
|
-
subscribeToEvents() {
|
39
|
-
if (!this.client) {
|
40
|
-
throw new Error("WC is not initialized");
|
41
|
-
}
|
42
|
-
this.client.on("session_update", ({ topic, params }) => {
|
43
|
-
const { namespaces } = params;
|
44
|
-
const session = this.client.session.get(topic);
|
45
|
-
const updatedSession = { ...session, namespaces };
|
46
|
-
this.onSessionConnected(updatedSession);
|
47
|
-
});
|
48
|
-
this.client.on("session_event", ({ topic, params }) => {
|
49
|
-
if (params.chainId.includes("hedera:")) {
|
50
|
-
this.$events.next(params.event);
|
51
|
-
}
|
52
|
-
});
|
53
|
-
}
|
54
|
-
async connect(ledgerId = LedgerId.MAINNET, activeTopic) {
|
55
|
-
if (!this.client) {
|
56
|
-
throw new Error("WC is not initialized");
|
57
|
-
}
|
58
|
-
if (this.session) {
|
59
|
-
const sessionNetworks = getLedgerIDsFromSession(this.session).map(l => l.toString());
|
60
|
-
if (sessionNetworks.includes(ledgerId.toString())) {
|
61
|
-
return;
|
62
|
-
}
|
63
|
-
}
|
64
|
-
return new Promise(async (resolve, reject) => {
|
65
|
-
try {
|
66
|
-
const requiredNamespaces = getRequiredNamespaces(ledgerId);
|
67
|
-
requiredNamespaces.hedera.events.push(...this.allowedEvents);
|
68
|
-
const { uri, approval } = await this.client.connect({
|
69
|
-
pairingTopic: activeTopic,
|
70
|
-
requiredNamespaces
|
71
|
-
});
|
72
|
-
if (uri) {
|
73
|
-
// @ts-ignore
|
74
|
-
QRCodeModal.open(uri, () => {
|
75
|
-
reject(new HWCError(402, "User rejected pairing", {}));
|
76
|
-
});
|
77
|
-
}
|
78
|
-
const session = await approval();
|
79
|
-
await this.onSessionConnected(session);
|
80
|
-
resolve();
|
81
|
-
}
|
82
|
-
catch (e) {
|
83
|
-
reject(e);
|
84
|
-
}
|
85
|
-
finally {
|
86
|
-
// @ts-ignore
|
87
|
-
QRCodeModal.close();
|
88
|
-
}
|
89
|
-
});
|
90
|
-
}
|
91
|
-
async prepareConnectURI(ledgerId = LedgerId.MAINNET, activeTopic) {
|
92
|
-
if (!this.client) {
|
93
|
-
throw new Error("WC is not initialized");
|
94
|
-
}
|
95
|
-
if (this.session) {
|
96
|
-
const sessionNetworks = getLedgerIDsFromSession(this.session).map(l => l.toString());
|
97
|
-
if (sessionNetworks.includes(ledgerId.toString())) {
|
98
|
-
return;
|
99
|
-
}
|
100
|
-
}
|
101
|
-
const requiredNamespaces = getRequiredNamespaces(ledgerId);
|
102
|
-
requiredNamespaces.hedera.events.push(...this.allowedEvents);
|
103
|
-
requiredNamespaces.hedera.methods.push(...this.extensionMethods);
|
104
|
-
return this.client.connect({
|
105
|
-
pairingTopic: activeTopic,
|
106
|
-
requiredNamespaces
|
107
|
-
});
|
108
|
-
}
|
109
|
-
async onSessionConnected(session) {
|
110
|
-
const allNamespaceAccounts = getAccountLedgerPairsFromSession(session);
|
111
|
-
this.session = session;
|
112
|
-
this.signers = allNamespaceAccounts.map(({ account, network }) => new WCSigner(AccountId.fromString(account), this.client, session.topic, network, getExtensionMethodsFromSession(session)));
|
113
|
-
}
|
114
|
-
getSigners() {
|
115
|
-
return this.signers;
|
116
|
-
}
|
117
|
-
}
|
118
|
-
//# sourceMappingURL=DAppConnector.js.map
|