From 8d9bed083d90f58957193bbd66101d6885fec98d Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Tue, 26 Mar 2024 11:25:02 +0200 Subject: [PATCH 1/8] cleanup + update unisat adapter --- README.md | 15 ++++++++++-- package-lock.json | 53 +++++++++++++++++++++++++++++++++--------- package.json | 7 +++--- src/adapters/index.ts | 22 ++++++++++++++++-- src/adapters/unisat.ts | 27 +++++++++++++++------ src/provider/index.ts | 20 ++++------------ 6 files changed, 103 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index de7b99b..2683aa9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,16 @@ -# @sats-connect/core +# `@sats-connect/core` Sats connect is a simple javascript library that connects apps to Bitcoin wallets like Xverse to retrieve user wallet addresses and sign transactions (PSBTs). -[Read the docs](https://docs.xverse.app/sats-connect/) + +# Building the `@sats-connect/core` package + +To build the `@sats-connect/core` package, run + +```bash +npm run build +``` + +# Docs + +[Developer Docs](https://docs.xverse.app/sats-connect/) diff --git a/package-lock.json b/package-lock.json index c3c50da..0953624 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,10 +9,8 @@ "version": "2.0.0", "license": "ISC", "dependencies": { - "bitcoin-address-validation": "^2.2.3", - "jsontokens": "^4.0.1", - "process": "^0.11.10", - "util": "^0.12.4" + "bitcoin-address-validation": "2.2.3", + "jsontokens": "4.0.1" }, "devDependencies": { "@types/jest": "^29.2.6", @@ -25,6 +23,7 @@ "ts-jest": "^29.0.5", "ts-loader": "^9.4.1", "typescript": "^4.9.4", + "util": "^0.12.4", "vm-browserify": "^1.1.2", "webpack": "^5.74.0", "webpack-cli": "^4.10.0" @@ -1562,6 +1561,7 @@ "version": "1.0.5", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", "integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -1795,6 +1795,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "dev": true, "dependencies": { "function-bind": "^1.1.1", "get-intrinsic": "^1.0.2" @@ -2407,6 +2408,7 @@ "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", + "dev": true, "dependencies": { "is-callable": "^1.1.3" } @@ -2435,7 +2437,8 @@ "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true }, "node_modules/gensync": { "version": "1.0.0-beta.2", @@ -2461,6 +2464,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.0.tgz", "integrity": "sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q==", + "dev": true, "dependencies": { "function-bind": "^1.1.1", "has": "^1.0.3", @@ -2532,6 +2536,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dev": true, "dependencies": { "get-intrinsic": "^1.1.3" }, @@ -2549,6 +2554,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, "dependencies": { "function-bind": "^1.1.1" }, @@ -2569,6 +2575,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -2580,6 +2587,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz", "integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==", + "dev": true, "dependencies": { "has-symbols": "^1.0.2" }, @@ -2664,7 +2672,8 @@ "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true }, "node_modules/interpret": { "version": "2.2.0", @@ -2679,6 +2688,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", + "dev": true, "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -2701,6 +2711,7 @@ "version": "1.2.7", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -2744,6 +2755,7 @@ "version": "1.0.10", "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.10.tgz", "integrity": "sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==", + "dev": true, "dependencies": { "has-tostringtag": "^1.0.0" }, @@ -2792,6 +2804,7 @@ "version": "1.1.10", "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.10.tgz", "integrity": "sha512-PJqgEHiWZvMpaFZ3uTc8kHPM4+4ADTlDniuQL7cU/UDA0Ql7F70yGfHph3cLNe+c9toaigv+DFzTJKhc2CtO6A==", + "dev": true, "dependencies": { "available-typed-arrays": "^1.0.5", "call-bind": "^1.0.2", @@ -5252,6 +5265,7 @@ "version": "0.12.5", "resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz", "integrity": "sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==", + "dev": true, "dependencies": { "inherits": "^2.0.3", "is-arguments": "^1.0.4", @@ -5461,6 +5475,7 @@ "version": "1.1.9", "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.9.tgz", "integrity": "sha512-w9c4xkx6mPidwp7180ckYWfMmvxpjlZuIudNtDf4N/tTAUB8VJbX25qZoAsrtGuYNnGw3pa0AXgbGKRB8/EceA==", + "dev": true, "dependencies": { "available-typed-arrays": "^1.0.5", "call-bind": "^1.0.2", @@ -6844,7 +6859,8 @@ "available-typed-arrays": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", - "integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==" + "integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==", + "dev": true }, "babel-jest": { "version": "29.4.3", @@ -7012,6 +7028,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "dev": true, "requires": { "function-bind": "^1.1.1", "get-intrinsic": "^1.0.2" @@ -7461,6 +7478,7 @@ "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", + "dev": true, "requires": { "is-callable": "^1.1.3" } @@ -7482,7 +7500,8 @@ "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true }, "gensync": { "version": "1.0.0-beta.2", @@ -7502,6 +7521,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.0.tgz", "integrity": "sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q==", + "dev": true, "requires": { "function-bind": "^1.1.1", "has": "^1.0.3", @@ -7552,6 +7572,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dev": true, "requires": { "get-intrinsic": "^1.1.3" } @@ -7566,6 +7587,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, "requires": { "function-bind": "^1.1.1" } @@ -7579,12 +7601,14 @@ "has-symbols": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", - "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==" + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "dev": true }, "has-tostringtag": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz", "integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==", + "dev": true, "requires": { "has-symbols": "^1.0.2" } @@ -7639,7 +7663,8 @@ "inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true }, "interpret": { "version": "2.2.0", @@ -7651,6 +7676,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", + "dev": true, "requires": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -7666,7 +7692,8 @@ "is-callable": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", - "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==" + "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", + "dev": true }, "is-core-module": { "version": "2.11.0", @@ -7695,6 +7722,7 @@ "version": "1.0.10", "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.10.tgz", "integrity": "sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==", + "dev": true, "requires": { "has-tostringtag": "^1.0.0" } @@ -7725,6 +7753,7 @@ "version": "1.1.10", "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.10.tgz", "integrity": "sha512-PJqgEHiWZvMpaFZ3uTc8kHPM4+4ADTlDniuQL7cU/UDA0Ql7F70yGfHph3cLNe+c9toaigv+DFzTJKhc2CtO6A==", + "dev": true, "requires": { "available-typed-arrays": "^1.0.5", "call-bind": "^1.0.2", @@ -9488,6 +9517,7 @@ "version": "0.12.5", "resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz", "integrity": "sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==", + "dev": true, "requires": { "inherits": "^2.0.3", "is-arguments": "^1.0.4", @@ -9638,6 +9668,7 @@ "version": "1.1.9", "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.9.tgz", "integrity": "sha512-w9c4xkx6mPidwp7180ckYWfMmvxpjlZuIudNtDf4N/tTAUB8VJbX25qZoAsrtGuYNnGw3pa0AXgbGKRB8/EceA==", + "dev": true, "requires": { "available-typed-arrays": "^1.0.5", "call-bind": "^1.0.2", diff --git a/package.json b/package.json index eb755c4..6c01be9 100644 --- a/package.json +++ b/package.json @@ -22,10 +22,8 @@ ] }, "dependencies": { - "bitcoin-address-validation": "^2.2.3", - "jsontokens": "^4.0.1", - "process": "^0.11.10", - "util": "^0.12.4" + "bitcoin-address-validation": "2.2.3", + "jsontokens": "4.0.1" }, "devDependencies": { "@types/jest": "^29.2.6", @@ -33,6 +31,7 @@ "lint-staged": "^13.2.3", "prettier": "^2.8.4", "process": "^0.11.10", + "util": "^0.12.4", "rimraf": "^3.0.2", "stream-browserify": "^3.0.0", "ts-jest": "^29.0.5", diff --git a/src/adapters/index.ts b/src/adapters/index.ts index f016823..2134af4 100644 --- a/src/adapters/index.ts +++ b/src/adapters/index.ts @@ -1,10 +1,28 @@ import { XverseAdapter } from './xverse'; import { SatsConnectAdapter } from './satsConnectAdapter'; import { UnisatAdapter } from './unisat'; +import { Provider } from '../provider'; + +export const DefaultAdaptersInfo: Record = { + xverse: { + id: 'XverseProviders.BitcoinProvider', + name: 'Xverse', + webUrl: 'https://www.xverse.app/', + chromeWebStoreUrl: + 'https://chromewebstore.google.com/detail/xverse-wallet/idnnbdplmphpflfnlkomgpfbpcgelopg', + icon: 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAyIiBoZWlnaHQ9IjEwMiIgdmlld0JveD0iMCAwIDEwMiAxMDIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGlkPSJJY29uX0FydCAoRWRpdCBNZSkiPgo8cmVjdCB3aWR0aD0iMTAyIiBoZWlnaHQ9IjEwMiIgZmlsbD0iIzE4MTgxOCIvPgo8ZyBpZD0iTG9nby9FbWJsZW0iIGNsaXAtcGF0aD0idXJsKCNjbGlwMF8yMF8xMjIzKSI+CjxwYXRoIGlkPSJWZWN0b3IiIGQ9Ik03NC42NTQyIDczLjg4ODNWNjUuMjMxMkM3NC42NTQyIDY0Ljg4OCA3NC41MTc3IDY0LjU2MDYgNzQuMjc0NSA2NC4zMTc0TDM3LjQzOTcgMjcuNDgyNUMzNy4xOTY1IDI3LjIzOTIgMzYuODY5MSAyNy4xMDI4IDM2LjUyNTggMjcuMTAyOEgyNy44NjlDMjcuNDQxNiAyNy4xMDI4IDI3LjA5MzggMjcuNDUwNiAyNy4wOTM4IDI3Ljg3OFYzNS45MjExQzI3LjA5MzggMzYuMjY0NCAyNy4yMzAyIDM2LjU5MTcgMjcuNDczNCAzNi44MzVMNDAuNjk1MiA1MC4wNTY3QzQwLjk5NzUgNTAuMzU5MSA0MC45OTc1IDUwLjg1MDEgNDAuNjk1MiA1MS4xNTI0TDI3LjMyMTEg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WxsPSJ3aGl0ZSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMzIgMTYpIi8+CjwvY2xpcFBhdGg+CjwvZGVmcz4KPC9zdmc+Cg==', + }, +}; export const defaultAdapters: Record SatsConnectAdapter> = { - 'XverseProviders.BitcoinProvider': XverseAdapter, - unisat: UnisatAdapter, + [DefaultAdaptersInfo.xverse.id]: XverseAdapter, + [DefaultAdaptersInfo.unisat.id]: UnisatAdapter, }; export * from './persistence'; diff --git a/src/adapters/unisat.ts b/src/adapters/unisat.ts index f88624f..0d9c54d 100644 --- a/src/adapters/unisat.ts +++ b/src/adapters/unisat.ts @@ -10,12 +10,12 @@ import { } from '../request'; import { SatsConnectAdapter } from './satsConnectAdapter'; import { RpcErrorCode, RpcResult } from '../types'; -import { getAddressInfo } from 'bitcoin-address-validation'; +import { AddressType, getAddressInfo } from 'bitcoin-address-validation'; type Unisat = { requestAccounts: () => Promise; getAccounts: () => Promise; - signMessage: (message: string, type?: string) => Promise; + signMessage: (message: string, type?: 'ecdsa' | 'bip322-simple') => Promise; getPublicKey: () => Promise; sendBitcoin: ( address: string, @@ -35,6 +35,7 @@ type Unisat = { }[]; } ) => Promise; + pushPsbt: (psbtHex: string) => Promise; }; declare global { @@ -71,11 +72,18 @@ class UnisatAdapter extends SatsConnectAdapter { private async signMessage(params: SignMessageParams): Promise> { const { message, address } = params; - // to-do handle the type optional parameter - const response = await window.unisat.signMessage(message); + const addressType = getAddressInfo(address).type; + if (addressType === AddressType.p2tr) { + const response = await window.unisat.signMessage(message, 'bip322-simple'); + return { + address, + messageHash: '', + signature: response, + }; + } + const response = await window.unisat.signMessage(message, 'ecdsa'); return { address, - // to-do: messageHash generation sats-connect responsibility? messageHash: '', signature: response, }; @@ -86,8 +94,6 @@ class UnisatAdapter extends SatsConnectAdapter { const response = await Promise.all( recipients.map((recipient) => window.unisat.sendBitcoin(recipient.address, recipient.amount)) ); - // to-do: handling multiple recipients - // xverse creates one transaction for all recipients, unisat creates one transaction for each recipient return { txid: response[0], }; @@ -109,6 +115,13 @@ class UnisatAdapter extends SatsConnectAdapter { // publicKey: '', })), }); + if (broadcast) { + const txid = await window.unisat.pushPsbt(psbtHex); + return { + psbt: psbtHex, + txid, + }; + } return { psbt: psbtHex, }; diff --git a/src/provider/index.ts b/src/provider/index.ts index d2d2ef7..444414a 100644 --- a/src/provider/index.ts +++ b/src/provider/index.ts @@ -1,3 +1,4 @@ +import { DefaultAdaptersInfo } from '../adapters'; import { type SupportedWallet, type BitcoinProvider, type Provider } from './types'; export async function getProviderOrThrow( @@ -28,24 +29,13 @@ export function isProviderInstalled(providerId: string) { export function getSupportedWallets(): SupportedWallet[] { const btc_providers = getProviders(); - // const adaptedWallets = [ - - // ]; - const unisat = { - id: 'unisat', - name: 'Unisat', - icon: 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTgwIiBoZWlnaHQ9IjE4MCIgdmlld0JveD0iMCAwIDE4MCAxODAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxODAiIGhlaWdodD0iMTgwIiBmaWxsPSJibGFjayIvPgo8ZyBjbGlwLXBhdGg9InVybCgjY2xpcDBfMTAwNTBfNDE3MSkiPgo8cGF0aCBkPSJNMTEzLjY2IDI5LjI4OTdMMTQzLjk3IDU5LjMwOTdDMTQ2LjU1IDYxLjg1OTcgMTQ3LjgyIDY0LjQzOTcgMTQ3Ljc4IDY3LjAzOTdDMTQ3Ljc0IDY5LjYzOTcgMTQ2LjYzIDcyLjAwOTcgMTQ0LjQ2IDc0LjE1OTdDMTQyLjE5IDc2LjQwOTcgMTM5Ljc0IDc3LjU0OTcgMTM3LjEyIDc3LjU5OTdDMTM0LjUgNzcuNjM5NyAxMzEuOSA3Ni4zNzk3IDEyOS4zMiA3My44Mjk3TDk4LjMxOTkgNDMuMTI5N0M5NC43OTk5IDM5LjYzOTcgOTEuMzk5OSAzNy4xNjk3ID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dCB3aWR0aD0iMTE1Ljc3IiBoZWlnaHQ9IjE0Ny43IiBmaWxsPSJ3aGl0ZSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMzIgMTYpIi8+CjwvY2xpcFBhdGg+CjwvZGVmcz4KPC9zdmc+Cg==', - url: 'https://unisat.io', - }; - btc_providers.push(unisat); + for (let key in DefaultAdaptersInfo) { + btc_providers.push(DefaultAdaptersInfo[key]); + } const wallets: SupportedWallet[] = btc_providers.map((provider) => { { return { - id: provider.id, - name: provider.name, - icon: provider.icon, - webUrl: provider.webUrl, - chromeWebStoreUrl: provider.chromeWebStoreUrl, + ...provider, isInstalled: isProviderInstalled(provider.id), }; } From 04929df3bdaa7ba84ea231ea59e9d7cbbecd5e32 Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Tue, 26 Mar 2024 14:02:01 +0200 Subject: [PATCH 2/8] update adapters interface --- src/adapters/BaseAdapter.ts | 15 ++------------- src/adapters/index.ts | 1 - src/adapters/persistence.ts | 11 ----------- src/adapters/satsConnectAdapter.ts | 4 ---- src/adapters/unisat.ts | 18 ------------------ src/adapters/xverse.ts | 13 ------------- src/provider/index.ts | 12 ++++++++++++ 7 files changed, 14 insertions(+), 60 deletions(-) delete mode 100644 src/adapters/persistence.ts diff --git a/src/adapters/BaseAdapter.ts b/src/adapters/BaseAdapter.ts index 7232ddc..2b358c4 100644 --- a/src/adapters/BaseAdapter.ts +++ b/src/adapters/BaseAdapter.ts @@ -6,27 +6,16 @@ import { Provider, getProviderById } from '../provider'; class BaseAdapter extends SatsConnectAdapter { id = ''; - name = ''; - url = ''; - supportedMethods: (keyof StxRequests | keyof BtcRequests)[] = []; - - constructor(providerInfo: Provider) { + constructor(providerId: string) { super(); - this.id = providerInfo.id; - this.name = providerInfo.name; - this.url = providerInfo.webUrl || ''; - this.supportedMethods = providerInfo.methods || []; + this.id = providerId; } request = async ( method: Method, params: Params ): Promise | undefined> => { - if (!this.supportedMethods.includes(method)) { - console.error('Method not supported by the selected wallet'); - } - return request(method, params, this.id); }; } diff --git a/src/adapters/index.ts b/src/adapters/index.ts index 2134af4..dbe0b2d 100644 --- a/src/adapters/index.ts +++ b/src/adapters/index.ts @@ -25,6 +25,5 @@ export const defaultAdapters: Record SatsConnectAdapter> = { [DefaultAdaptersInfo.unisat.id]: UnisatAdapter, }; -export * from './persistence'; export * from './satsConnectAdapter'; export * from './BaseAdapter'; diff --git a/src/adapters/persistence.ts b/src/adapters/persistence.ts deleted file mode 100644 index 92956e8..0000000 --- a/src/adapters/persistence.ts +++ /dev/null @@ -1,11 +0,0 @@ -export function setDefaultProvider(providerId: string) { - localStorage.setItem('sats-connect_defaultProvider', providerId); -} - -export function getDefaultProvider() { - return localStorage.getItem('sats-connect_defaultProvider'); -} - -export function removeDefaultProvider() { - localStorage.removeItem('sats-connect_defaultProvider'); -} diff --git a/src/adapters/satsConnectAdapter.ts b/src/adapters/satsConnectAdapter.ts index d87b698..c7b6c3b 100644 --- a/src/adapters/satsConnectAdapter.ts +++ b/src/adapters/satsConnectAdapter.ts @@ -3,10 +3,6 @@ import { RpcResult } from '../types'; abstract class SatsConnectAdapter { abstract readonly id: string; - abstract readonly name: string; - abstract url: string; - - supportedMethods: (StxRequestMethod | BtcRequestMethod)[] = []; abstract request( method: Method, diff --git a/src/adapters/unisat.ts b/src/adapters/unisat.ts index 0d9c54d..1de3a11 100644 --- a/src/adapters/unisat.ts +++ b/src/adapters/unisat.ts @@ -46,22 +46,12 @@ declare global { class UnisatAdapter extends SatsConnectAdapter { id = 'unisat'; - name = 'Unisat'; - url = 'https://unisat.io/'; - - supportedMethods: (keyof StxRequests | keyof BtcRequests)[] = [ - 'getAccounts', - 'sendTransfer', - 'signMessage', - 'signPsbt', - ]; private async getAccounts(): Promise> { const [accounts, publickKey] = await Promise.all([ window.unisat.requestAccounts(), window.unisat.getPublicKey(), ]); - // to-do: create a generic purpose type for the response const response: Return<'getAccounts'> = accounts.map((address) => ({ address, publicKey: publickKey, @@ -108,11 +98,6 @@ class UnisatAdapter extends SatsConnectAdapter { address, index: indexes[0], sighashTypes: allowedSignHash ? [allowedSignHash] : undefined, - /** - * to-do: get the public key from the address - */ - // disableTweakSigner: true, - // publicKey: '', })), }); if (broadcast) { @@ -131,9 +116,6 @@ class UnisatAdapter extends SatsConnectAdapter { method: Method, params: Params ): Promise | undefined> => { - if (!this.supportedMethods.includes(method)) { - console.error('Method not supported by the selected wallet'); - } try { switch (method) { case 'getAccounts': { diff --git a/src/adapters/xverse.ts b/src/adapters/xverse.ts index 4f6519d..6b9bf36 100644 --- a/src/adapters/xverse.ts +++ b/src/adapters/xverse.ts @@ -5,24 +5,11 @@ import { RpcResult } from '../types'; class XverseAdapter extends SatsConnectAdapter { id = 'XverseProviders.BitcoinProvider'; - name = 'Xverse'; - url = 'xverse.app'; - - supportedMethods: (keyof StxRequests | keyof BtcRequests)[] = [ - 'getAccounts', - 'sendTransfer', - 'signMessage', - 'signPsbt', - ]; request = async ( method: Method, params: Params ): Promise | undefined> => { - if (!this.supportedMethods.includes(method)) { - console.error('Method not supported by the selected wallet'); - } - return request(method, params, this.id); }; } diff --git a/src/provider/index.ts b/src/provider/index.ts index 444414a..9069d6f 100644 --- a/src/provider/index.ts +++ b/src/provider/index.ts @@ -27,6 +27,18 @@ export function isProviderInstalled(providerId: string) { return !!getProviderById(providerId); } +export function setDefaultProvider(providerId: string) { + localStorage.setItem('sats-connect_defaultProvider', providerId); +} + +export function getDefaultProvider() { + return localStorage.getItem('sats-connect_defaultProvider'); +} + +export function removeDefaultProvider() { + localStorage.removeItem('sats-connect_defaultProvider'); +} + export function getSupportedWallets(): SupportedWallet[] { const btc_providers = getProviders(); for (let key in DefaultAdaptersInfo) { From 57de1f9f6c61efb75ceb07da2239d79e1e064bf5 Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Tue, 26 Mar 2024 14:48:47 +0200 Subject: [PATCH 3/8] update cicd --- .github/workflows/release-package.yml | 2 +- .github/workflows/release-pull-request.yml | 4 ++-- package.json | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release-package.yml b/.github/workflows/release-package.yml index 9605fbe..cc478be 100644 --- a/.github/workflows/release-package.yml +++ b/.github/workflows/release-package.yml @@ -45,4 +45,4 @@ jobs: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} run: | VERSION=$(npm pkg get version | jq . -r) - npm dist-tag add sats-connect@$VERSION latest + npm dist-tag add @sats-connect/core@$VERSION latest diff --git a/.github/workflows/release-pull-request.yml b/.github/workflows/release-pull-request.yml index 2dc2ecd..02e64e8 100644 --- a/.github/workflows/release-pull-request.yml +++ b/.github/workflows/release-pull-request.yml @@ -13,7 +13,7 @@ jobs: is-not-fork: ${{ steps.check.outputs.is_not_fork }} steps: - id: check - run: echo "::set-output name=is_not_fork::${{ github.repository == 'secretkeylabs/sats-connect' }}" + run: echo "::set-output name=is_not_fork::${{ github.repository == 'secretkeylabs/sats-connect-core' }}" test: runs-on: ubuntu-latest @@ -101,4 +101,4 @@ jobs: -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token $GITHUB_TOKEN" \ $GITHUB_URL \ - -d "{\"body\":\"> Test this PR with \`npm i --save-exact sats-connect@$VERSION\`\"}" + -d "{\"body\":\"> Test this PR with \`npm i --save-exact @sats-connect/core@$VERSION\`\"}" diff --git a/package.json b/package.json index 6c01be9..9c5fd02 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sats-connect/core", - "version": "2.0.0", + "version": "0.0.1", "main": "dist/index.js", "files": [ "dist" @@ -43,12 +43,12 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/secretkeylabs/sats-connect.git" + "url": "git+https://github.com/secretkeylabs/sats-connect-core.git" }, "author": "Secret Key Labs", "license": "ISC", "bugs": { - "url": "https://github.com/secretkeylabs/sats-connect/issues" + "url": "https://github.com/secretkeylabs/sats-connect-core.git/issues" }, - "homepage": "https://github.com/secretkeylabs/sats-connect#readme" + "homepage": "https://github.com/secretkeylabs/sats-connect-core.git#readme" } From 7954e18f8b0ecd1feba4982df31470af30068341 Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Tue, 26 Mar 2024 14:51:06 +0200 Subject: [PATCH 4/8] fix typo --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9c5fd02..cbc946e 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "author": "Secret Key Labs", "license": "ISC", "bugs": { - "url": "https://github.com/secretkeylabs/sats-connect-core.git/issues" + "url": "https://github.com/secretkeylabs/sats-connect-core/issues" }, - "homepage": "https://github.com/secretkeylabs/sats-connect-core.git#readme" + "homepage": "https://github.com/secretkeylabs/sats-connect-core#readme" } From d401418b907f924a3b4d020f9429775fcfbe5ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduard=20Bardaj=C3=AD=20Puig?= Date: Tue, 26 Mar 2024 15:22:32 +0100 Subject: [PATCH 5/8] Omit Xverse --- package-lock.json | 48 ++++++++++++++++++++++++++++++++++++++++--- package.json | 6 ++++-- src/provider/index.ts | 3 ++- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0953624..bda1b5b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,21 @@ { "name": "@sats-connect/core", - "version": "2.0.0", + "version": "0.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@sats-connect/core", - "version": "2.0.0", + "version": "0.0.1", "license": "ISC", "dependencies": { "bitcoin-address-validation": "2.2.3", - "jsontokens": "4.0.1" + "jsontokens": "4.0.1", + "lodash.omit": "4.5.0" }, "devDependencies": { "@types/jest": "^29.2.6", + "@types/lodash.omit": "4.5.9", "husky": "^8.0.3", "lint-staged": "^13.2.3", "prettier": "^2.8.4", @@ -1218,6 +1220,21 @@ "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "dev": true }, + "node_modules/@types/lodash": { + "version": "4.17.0", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.0.tgz", + "integrity": "sha512-t7dhREVv6dbNj0q17X12j7yDG4bD/DHYX7o5/DbDxobP0HnGPgpRz2Ej77aL7TZT3DSw13fqUTj8J4mMnqa7WA==", + "dev": true + }, + "node_modules/@types/lodash.omit": { + "version": "4.5.9", + "resolved": "https://registry.npmjs.org/@types/lodash.omit/-/lodash.omit-4.5.9.tgz", + "integrity": "sha512-zuAVFLUPJMOzsw6yawshsYGgq2hWUHtsZgeXHZmSFhaQQFC6EQ021uDKHkSjOpNhSvtNSU9165/o3o/Q51GpTw==", + "dev": true, + "dependencies": { + "@types/lodash": "*" + } + }, "node_modules/@types/node": { "version": "18.14.2", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.14.2.tgz", @@ -3923,6 +3940,11 @@ "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", "dev": true }, + "node_modules/lodash.omit": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.omit/-/lodash.omit-4.5.0.tgz", + "integrity": "sha512-XeqSp49hNGmlkj2EJlfrQFIzQ6lXdNro9sddtQzcJY8QaoC2GO0DT7xaIokHeyM+mIT0mPMlPvkYzg2xCuHdZg==" + }, "node_modules/log-update": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/log-update/-/log-update-5.0.1.tgz", @@ -6562,6 +6584,21 @@ "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "dev": true }, + "@types/lodash": { + "version": "4.17.0", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.0.tgz", + "integrity": "sha512-t7dhREVv6dbNj0q17X12j7yDG4bD/DHYX7o5/DbDxobP0HnGPgpRz2Ej77aL7TZT3DSw13fqUTj8J4mMnqa7WA==", + "dev": true + }, + "@types/lodash.omit": { + "version": "4.5.9", + "resolved": "https://registry.npmjs.org/@types/lodash.omit/-/lodash.omit-4.5.9.tgz", + "integrity": "sha512-zuAVFLUPJMOzsw6yawshsYGgq2hWUHtsZgeXHZmSFhaQQFC6EQ021uDKHkSjOpNhSvtNSU9165/o3o/Q51GpTw==", + "dev": true, + "requires": { + "@types/lodash": "*" + } + }, "@types/node": { "version": "18.14.2", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.14.2.tgz", @@ -8579,6 +8616,11 @@ "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", "dev": true }, + "lodash.omit": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.omit/-/lodash.omit-4.5.0.tgz", + "integrity": "sha512-XeqSp49hNGmlkj2EJlfrQFIzQ6lXdNro9sddtQzcJY8QaoC2GO0DT7xaIokHeyM+mIT0mPMlPvkYzg2xCuHdZg==" + }, "log-update": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/log-update/-/log-update-5.0.1.tgz", diff --git a/package.json b/package.json index cbc946e..e872a73 100644 --- a/package.json +++ b/package.json @@ -23,20 +23,22 @@ }, "dependencies": { "bitcoin-address-validation": "2.2.3", - "jsontokens": "4.0.1" + "jsontokens": "4.0.1", + "lodash.omit": "4.5.0" }, "devDependencies": { "@types/jest": "^29.2.6", + "@types/lodash.omit": "4.5.9", "husky": "^8.0.3", "lint-staged": "^13.2.3", "prettier": "^2.8.4", "process": "^0.11.10", - "util": "^0.12.4", "rimraf": "^3.0.2", "stream-browserify": "^3.0.0", "ts-jest": "^29.0.5", "ts-loader": "^9.4.1", "typescript": "^4.9.4", + "util": "^0.12.4", "vm-browserify": "^1.1.2", "webpack": "^5.74.0", "webpack-cli": "^4.10.0" diff --git a/src/provider/index.ts b/src/provider/index.ts index 9069d6f..b527a84 100644 --- a/src/provider/index.ts +++ b/src/provider/index.ts @@ -1,5 +1,6 @@ import { DefaultAdaptersInfo } from '../adapters'; import { type SupportedWallet, type BitcoinProvider, type Provider } from './types'; +import omit from 'lodash.omit'; export async function getProviderOrThrow( getProvider?: () => Promise @@ -41,7 +42,7 @@ export function removeDefaultProvider() { export function getSupportedWallets(): SupportedWallet[] { const btc_providers = getProviders(); - for (let key in DefaultAdaptersInfo) { + for (const key in omit(DefaultAdaptersInfo, ['xverse'])) { btc_providers.push(DefaultAdaptersInfo[key]); } const wallets: SupportedWallet[] = btc_providers.map((provider) => { From 31ca13355626a66ece0919b7147cafea097df8e9 Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Tue, 26 Mar 2024 18:13:48 +0200 Subject: [PATCH 6/8] finalize unisat adapter --- .github/workflows/build-and-publish-pr.yml | 40 ++++++++ .github/workflows/release-pull-request.yml | 104 --------------------- src/adapters/BaseAdapter.ts | 3 +- src/adapters/satsConnectAdapter.ts | 2 +- src/adapters/unisat.ts | 89 +++++++++++++----- src/adapters/xverse.ts | 2 +- src/request/types/btcMethods.ts | 17 +++- src/request/types/stxMethods.ts | 3 +- 8 files changed, 124 insertions(+), 136 deletions(-) create mode 100644 .github/workflows/build-and-publish-pr.yml delete mode 100644 .github/workflows/release-pull-request.yml diff --git a/.github/workflows/build-and-publish-pr.yml b/.github/workflows/build-and-publish-pr.yml new file mode 100644 index 0000000..26fae6c --- /dev/null +++ b/.github/workflows/build-and-publish-pr.yml @@ -0,0 +1,40 @@ +name: Build and Publish NPM package + +on: + pull_request: + +jobs: + build-and-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: npm ci + + - name: Run build + run: npm run build + + - id: current-version + name: Get current version + run: echo "CURRENT_VERSION=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT + + - id: sha + name: Get commit sha + run: echo "SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Set publish version + run: npm version --no-git-tag-version $CURRENT_VERSION-$SHA + env: + SHA: ${{ steps.sha.outputs.SHA }} + CURRENT_VERSION: ${{ steps.current-version.outputs.CURRENT_VERSION }} + + - name: Publish to NPM package registry + run: npm publish --access=public --tag pr-$PR_NUMBER + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }} + PR_NUMBER: ${{ github.event.number }} diff --git a/.github/workflows/release-pull-request.yml b/.github/workflows/release-pull-request.yml deleted file mode 100644 index 02e64e8..0000000 --- a/.github/workflows/release-pull-request.yml +++ /dev/null @@ -1,104 +0,0 @@ -name: Release & Publish Package - -on: - pull_request: - branches: [develop] - - workflow_dispatch: - -jobs: - fork-check: - runs-on: ubuntu-latest - outputs: - is-not-fork: ${{ steps.check.outputs.is_not_fork }} - steps: - - id: check - run: echo "::set-output name=is_not_fork::${{ github.repository == 'secretkeylabs/sats-connect-core' }}" - - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: npm - - run: npm ci - # TODO: enable linting once ready - # - run: npm run lint - # - run: npm test - - publish-beta: - needs: - - test - - fork-check - if: needs.fork-check.outputs.is-not-fork == 'true' - runs-on: ubuntu-latest - permissions: - packages: write - contents: read - pull-requests: write - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: npm - registry-url: https://registry.npmjs.org - - - id: git-commit - run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - - - run: npm ci - - run: npm run build - - - id: current-version - run: echo "version=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT - - id: tag-version - run: npm version --no-git-tag-version $CURRENT_VERSION-$SHA - env: - SHA: ${{ steps.git-commit.outputs.sha }} - CURRENT_VERSION: ${{ steps.current-version.outputs.version }} - - - id: publish - run: npm publish --access=public --tag pr - env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} - - - id: published-version - run: echo "version=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT - - run: echo published version $VERSION - env: - VERSION: ${{ steps.published-version.outputs.version }} - - - name: Delete old bot comments - if: ${{ github.event_name == 'pull_request' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_ID: ${{ github.event.pull_request.number }} - REPO: ${{ github.repository }} - run: | - curl \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: token $GITHUB_TOKEN" \ - https://api.github.com/repos/$REPO/issues/$PR_ID/comments \ - | jq ".[] | select(.user.login==\"github-actions[bot]\") | .id" \ - | xargs -I %q curl \ - -L \ - -X DELETE \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: token $GITHUB_TOKEN"\ - https://api.github.com/repos/$REPO/issues/comments/%q - - name: Post test package PR comment - if: ${{ github.event_name == 'pull_request' }} - env: - VERSION: ${{ steps.published-version.outputs.version }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_URL: ${{ github.event.pull_request.comments_url }} - run: | - curl \ - -X POST \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: token $GITHUB_TOKEN" \ - $GITHUB_URL \ - -d "{\"body\":\"> Test this PR with \`npm i --save-exact @sats-connect/core@$VERSION\`\"}" diff --git a/src/adapters/BaseAdapter.ts b/src/adapters/BaseAdapter.ts index 2b358c4..8fce541 100644 --- a/src/adapters/BaseAdapter.ts +++ b/src/adapters/BaseAdapter.ts @@ -1,8 +1,7 @@ -import { BtcRequests, Params, Requests, StxRequests } from '../request'; +import { Params, Requests } from '../request'; import { SatsConnectAdapter } from './satsConnectAdapter'; import { request } from '../request'; import { RpcResult } from '../types'; -import { Provider, getProviderById } from '../provider'; class BaseAdapter extends SatsConnectAdapter { id = ''; diff --git a/src/adapters/satsConnectAdapter.ts b/src/adapters/satsConnectAdapter.ts index c7b6c3b..0c9fcb8 100644 --- a/src/adapters/satsConnectAdapter.ts +++ b/src/adapters/satsConnectAdapter.ts @@ -1,4 +1,4 @@ -import { BtcRequestMethod, Params, Requests, StxRequestMethod } from '../request'; +import { Params, Requests } from '../request'; import { RpcResult } from '../types'; abstract class SatsConnectAdapter { diff --git a/src/adapters/unisat.ts b/src/adapters/unisat.ts index 1de3a11..cb2bf98 100644 --- a/src/adapters/unisat.ts +++ b/src/adapters/unisat.ts @@ -1,16 +1,24 @@ import { - BtcRequests, + GetAccountsParams, Params, Requests, Return, SendTransferParams, SignMessageParams, SignPsbtParams, - StxRequests, } from '../request'; import { SatsConnectAdapter } from './satsConnectAdapter'; import { RpcErrorCode, RpcResult } from '../types'; import { AddressType, getAddressInfo } from 'bitcoin-address-validation'; +import { Address, AddressPurpose } from '../addresses'; + +type InputType = { + index: number; + address?: string; + publicKey?: string; + sighashTypes?: number[]; + disableTweakSigner?: boolean; +}[]; type Unisat = { requestAccounts: () => Promise; @@ -26,13 +34,7 @@ type Unisat = { psbtHex: string, options?: { autoFinalized?: boolean; - toSignInputs: { - index: number; - address?: string; - publicKey?: string; - sighashTypes?: number[]; - disableTweakSigner?: boolean; - }[]; + toSignInputs: InputType; } ) => Promise; pushPsbt: (psbtHex: string) => Promise; @@ -44,26 +46,65 @@ declare global { } } +function convertSignInputsToInputType( + signInputs: Record, + allowedSignHash?: number +): InputType { + let result: InputType = []; + for (let address in signInputs) { + let indexes = signInputs[address]; + for (let index of indexes) { + result.push({ + index: index, + address: address, + sighashTypes: allowedSignHash ? [allowedSignHash] : undefined, + }); + } + } + return result; +} + class UnisatAdapter extends SatsConnectAdapter { id = 'unisat'; - private async getAccounts(): Promise> { - const [accounts, publickKey] = await Promise.all([ + private async getAccounts(params: GetAccountsParams): Promise> { + const { purposes } = params; + if (!purposes.includes(AddressPurpose.Stacks)) { + throw new Error('Only bitcoin addresses are supported'); + } + const [accounts, publicKey] = await Promise.all([ window.unisat.requestAccounts(), window.unisat.getPublicKey(), ]); - const response: Return<'getAccounts'> = accounts.map((address) => ({ + const address = accounts[0]; + const addressType = getAddressInfo(accounts[0]).type; + const paymentAddress: Address = { address, - publicKey: publickKey, - addressType: getAddressInfo(address).type, - })); + publicKey, + addressType, + purpose: AddressPurpose.Payment, + }; + const ordinalsAddress: Address = { + address, + publicKey, + addressType, + purpose: AddressPurpose.Ordinals, + }; + const response: Return<'getAccounts'> = []; + if (purposes.includes(AddressPurpose.Payment)) { + response.push(paymentAddress); + } + if (purposes.includes(AddressPurpose.Ordinals)) { + response.push(ordinalsAddress); + } return response; } private async signMessage(params: SignMessageParams): Promise> { const { message, address } = params; const addressType = getAddressInfo(address).type; - if (addressType === AddressType.p2tr) { + const Bip322supportedTypes = [AddressType.p2wpkh, AddressType.p2tr]; + if (Bip322supportedTypes.includes(addressType)) { const response = await window.unisat.signMessage(message, 'bip322-simple'); return { address, @@ -91,19 +132,15 @@ class UnisatAdapter extends SatsConnectAdapter { private async signPsbt(params: SignPsbtParams): Promise> { const { psbt, signInputs, allowedSignHash, broadcast } = params; - // to-do: convert psbt from base64 to hex - const psbtHex = await window.unisat.signPsbt(psbt, { + const psbtHex = Buffer.from(psbt, 'base64').toString('hex'); + const signedPsbt = await window.unisat.signPsbt(psbtHex, { autoFinalized: broadcast, - toSignInputs: Object.entries(signInputs).map(([address, indexes]) => ({ - address, - index: indexes[0], - sighashTypes: allowedSignHash ? [allowedSignHash] : undefined, - })), + toSignInputs: convertSignInputsToInputType(signInputs, allowedSignHash), }); if (broadcast) { const txid = await window.unisat.pushPsbt(psbtHex); return { - psbt: psbtHex, + psbt: signedPsbt, txid, }; } @@ -119,7 +156,9 @@ class UnisatAdapter extends SatsConnectAdapter { try { switch (method) { case 'getAccounts': { - const response: Return<'getAccounts'> = await this.getAccounts(); + const response: Return<'getAccounts'> = await this.getAccounts( + params as GetAccountsParams + ); return { status: 'success', result: response as Return, diff --git a/src/adapters/xverse.ts b/src/adapters/xverse.ts index 6b9bf36..ed998f0 100644 --- a/src/adapters/xverse.ts +++ b/src/adapters/xverse.ts @@ -1,4 +1,4 @@ -import { BtcRequests, Params, Requests, StxRequests } from '../request'; +import { Params, Requests } from '../request'; import { SatsConnectAdapter } from './satsConnectAdapter'; import { request } from '../request'; import { RpcResult } from '../types'; diff --git a/src/request/types/btcMethods.ts b/src/request/types/btcMethods.ts index 36abd47..7499985 100644 --- a/src/request/types/btcMethods.ts +++ b/src/request/types/btcMethods.ts @@ -124,6 +124,21 @@ export type SignPsbtResult = { export type SignPsbt = MethodParamsAndResult; +export type GetAccountsParams = { + /** + * The purposes for which to generate addresses. + * possible values are "payment", "ordinals", ... + */ + purposes: Array; + /** + * a message to be displayed to the user in the request prompt. + */ + /** + * a message to be displayed to the user in the request prompt. + */ + message?: string; +}; + export type GetAccountResult = Address[]; -export type GetAccounts = MethodParamsAndResult; +export type GetAccounts = MethodParamsAndResult; diff --git a/src/request/types/stxMethods.ts b/src/request/types/stxMethods.ts index eb348cf..2f31186 100644 --- a/src/request/types/stxMethods.ts +++ b/src/request/types/stxMethods.ts @@ -247,11 +247,10 @@ export type DeployContractResult = TxId & Transaction; export type StxDeployContract = MethodParamsAndResult; // Types for `stx_getAccounts` request -export type GetAccountsParams = {}; export type GetAccountsResult = { addresses: Array
; }; -export type StxGetAccounts = MethodParamsAndResult; +export type StxGetAccounts = MethodParamsAndResult<{}, GetAccountsResult>; // Types for `stx_getAddresses` request export type GetAddressesParams = undefined | null; From 3b626fecf164b5ad701cc71fcf3d620eb2dcef38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduard=20Bardaj=C3=AD=20Puig?= Date: Tue, 26 Mar 2024 14:53:42 +0100 Subject: [PATCH 7/8] Add create default config --- package.json | 3 ++- src/index.ts | 5 +++-- src/ui/index.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 src/ui/index.ts diff --git a/package.json b/package.json index e872a73..21b8f96 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "dependencies": { "bitcoin-address-validation": "2.2.3", "jsontokens": "4.0.1", - "lodash.omit": "4.5.0" + "lodash.omit": "4.5.0", + "@sats-connect/ui": "*" }, "devDependencies": { "@types/jest": "^29.2.6", diff --git a/src/index.ts b/src/index.ts index 9be9eca..c4d10f1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,10 @@ -export * from './addresses'; -export * from './request'; export * from './adapters'; +export * from './addresses'; export * from './capabilities'; export * from './inscriptions'; export * from './messages'; export * from './provider'; +export * from './request'; export * from './transactions'; export * from './types'; +export * from './ui'; diff --git a/src/ui/index.ts b/src/ui/index.ts new file mode 100644 index 0000000..977ec6a --- /dev/null +++ b/src/ui/index.ts @@ -0,0 +1,44 @@ +import { Config } from '@sats-connect/ui'; +import { SupportedWallet } from 'src/provider'; + +export const xverseIcon = + 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAyIiBoZWlnaHQ9IjEwMiIgdmlld0JveD0iMCAwIDEwMiAxMDIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGlkPSJJY29uX0FydCAoRWRpdCBNZSkiPgo8cmVjdCB3aWR0aD0iMTAyIiBoZWlnaHQ9IjEwMiIgZmlsbD0iIzE4MTgxOCIvPgo8ZyBpZD0iTG9nby9FbWJsZW0iIGNsaXAtcGF0aD0idXJsKCNjbGlwMF8yMF8xMjIzKSI+CjxwYXRoIGlkPSJWZWN0b3IiIGQ9Ik03NC42NTQyIDczLjg4ODNWNjUuMjMxMkM3NC42NTQyIDY0Ljg4OCA3NC41MTc3IDY0LjU2MDYgNzQuMjc0NSA2NC4zMTc0TDM3LjQzOTcgMjcuNDgyNUMzNy4xOTY1IDI3LjIzOTIgMzYuODY5MSAyNy4xMDI4IDM2LjUyNTggMjcuMTAyOEgyNy44NjlDMjcuNDQxNiAyNy4xMDI4IDI3LjA5M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gxNiAzNi42MzcxVjI3LjkxODlDNzQuODgxNiAyNy40ODkyIDc0LjUzMzQgMjcuMTM5MSA3NC4xMDE3IDI3LjEzOTFMNjUuMjUzOCAyNy4xMjc3QzY1LjA0NyAyNy4xMjc3IDY0Ljg0OTIgMjcuMjA5NiA2NC43MDE0IDI3LjM1NTFMNTQuODA1NiAzNy4yMzVDNTQuMzE0NSAzNy43MjYgNTQuNjYyMyAzOC41NjcyIDU1LjM1NTcgMzguNTY3Mkg1NS4zNThaIiBmaWxsPSIjRUU3QTMwIi8+CjwvZz4KPC9nPgo8ZGVmcz4KPGNsaXBQYXRoIGlkPSJjbGlwMF8yMF8xMjIzIj4KPHJlY3Qgd2lkdGg9IjQ3LjgxMjUiIGhlaWdodD0iNDcuODEyNSIgZmlsbD0id2hpdGUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDI3LjA5MzggMjcuMDkzOCkiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K'; + +export function createDefaultConfig(providers: SupportedWallet[]): Config { + const config: Config = { providers: [] }; + // Xverse + const xverseProvider = providers.find( + (provider) => provider.id === 'XverseProviders.BitcoinProvider' + ); + config.providers.push( + xverseProvider + ? xverseProvider + : { + id: 'XverseProviders.BitcoinProvider', + name: 'Xverse', + icon: xverseIcon, + isInstalled: false, + chromeWebStoreUrl: + 'https://chromewebstore.google.com/detail/xverse-wallet/idnnbdplmphpflfnlkomgpfbpcgelopg', + googlePlayStoreUrl: + 'https://play.google.com/store/apps/details?id=com.secretkeylabs.xverse', + iOSAppStoreUrl: 'https://apps.apple.com/app/xverse-bitcoin-web3-wallet/id1552272513', + webUrl: 'https://www.xverse.app/', + } + ); + + // Unisat + const unisatProvider = providers.find((provider) => provider.id === 'unisat'); + if (unisatProvider && unisatProvider.isInstalled) { + config.providers.push(unisatProvider); + } + + // Rest + config.providers.concat( + providers.filter((provider) => { + return provider.id !== 'xverseProviders.bitcoinProvider' && provider.id !== 'unisat'; + }) + ); + + return config; +} From 32ab0f9080dccb530321179b9efde7e9f8adec70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduard=20Bardaj=C3=AD=20Puig?= Date: Wed, 27 Mar 2024 11:47:11 +0100 Subject: [PATCH 8/8] Foo --- foo.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 foo.txt diff --git a/foo.txt b/foo.txt new file mode 100644 index 0000000..1910281 --- /dev/null +++ b/foo.txt @@ -0,0 +1 @@ +foo \ No newline at end of file