From 178344ba939866f93682256bc523ad2a6108bbef Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 8 Feb 2024 15:39:38 -0300 Subject: [PATCH 01/14] Add documentation files --- README.md | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++- test.html | 95 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 189 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 6c7c649..8641c70 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ you want to contribute. # How to implement Simple Signer on your website -Simple Signer provides two endpoints, `/connect` and `/sign` which allow some customisations to be made. +Simple Signer provides three endpoints, `/connect`, `/sign` and `/payment` which allow some customisations to be made. To see an example of all the implementation properties please take a look at the [test.html](./test.html) file provided in this repo. @@ -329,6 +329,118 @@ Sometimes it's useful to group operations together to explain what they are doin --- +## Making a payment + +To make a payment using Simple Signer, you need to provide the necessary parameters either through the URL or using the `postMessage` method. Follow the steps below to integrate the payment functionality into your web application: + +### Step 1: Specify Payment Parameters + +You can pass the payment parameters such as the receiver's account, amount, asset type, and issuer through the URL or `postMessage` method. Here's an example of how you can do it: + +```html + + + + + + Simple Signer - Make Payment Demo + + + + +

Make Payment

+

+ This page demonstrates the process of making a payment using the + Simple Signer. +

+

Usage

+

Click the "Make Payment" button to initiate the payment process.

+ + + + + +``` + +You may choose to pass the payment parameters to Simple Signer either via URL or via postMessage. + +Via URL: + +```javascript +const receiver = 'Receiver public key'; +const amount = '10'; +const assetType = 'native'; // 'native' for XLM, or asset code for other assets +const issuer = ''; // If assetType is not 'native', provide issuer's public key + +const paymentWindow = window.open( + `https://sign.scalemote.io/payment/?receiver=${receiver}&amount=${amount}&assetType=${assetType}&issuer=${issuer}`, + 'Payment_Window', + 'width=360, height=700', +); +``` + +Via PostMessage: + +Post Message has some advantages over the URL method which are covered in the Payment API section. + +```javascript +const receiver = 'Receiver public key'; +const amount = '10'; +const assetType = 'native'; // 'native' for XLM, or asset code for other assets +const issuer = ''; // If assetType is not 'native', provide issuer's public key + +const simpleSignerUrl = 'https://sign.scalemote.io'; +const paymentWindow = window.open( + `${simpleSignerUrl}/payment`, + 'Payment_Window', + 'width=360, height=700', +); + +window.addEventListener('message', (e) => { + if ( + e.origin !== simpleSignerUrl && + e.data.type === 'onReady' && + e.data.page === 'payment' + ) { + paymentWindow.postMessage( + { receiver, amount, assetType, issuer }, + simpleSignerUrl, + ); + } +}); +``` + ## Language selection By default, Simple Signer will detect the browser's language and serve Simple Signer using this configuration. If the diff --git a/test.html b/test.html index 1c3244d..fe2b8f1 100644 --- a/test.html +++ b/test.html @@ -16,13 +16,21 @@ + + + +{#if paymentResultMessage} +
+
{paymentResultMessage}
+ +
+{:else} +
+ {#if !receiver || !amount || !assetType || !issuer} +

{$language.ERROR}

+
+

{$language.ERROR_MISSING_RECEIVER_DATA}

+ +
+ {:else} +

{$language.PAY}

+
+
+

{$language.NETWORK}:

+

{CURRENT_STELLAR_NETWORK}

+
+
+
+ {$language.YOU_ARE_PAYING} + {amount} + {assetType === 'native' ? 'XLM' : { assetType }} + {$language.TO_THE_ACCOUNT} +
+ {receiver}. +
+ + {#if wallet} +
+ + +
+ {:else} +
+

{$language.USER_IS_NOT_CONNECTED}

+ +
+ {/if} + {/if} +
+{/if} + + From 88bb2fa7c55c3ad1b62964d31f785f6e923d5e87 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 8 Feb 2024 17:05:58 -0300 Subject: [PATCH 07/14] Add stellar utils --- src/lib/stellar/utils/index.ts | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/lib/stellar/utils/index.ts diff --git a/src/lib/stellar/utils/index.ts b/src/lib/stellar/utils/index.ts new file mode 100644 index 0000000..2f3c7eb --- /dev/null +++ b/src/lib/stellar/utils/index.ts @@ -0,0 +1,5 @@ +import { Horizon } from 'stellar-sdk'; + +import { HORIZON_URL } from '../../../constants'; + +export const server = new Horizon.Server(HORIZON_URL); From bdf248cc21161c23d83931a4d31f91d2530a1209 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 8 Feb 2024 17:06:34 -0300 Subject: [PATCH 08/14] Add redirect to Connect.svelte --- src/routes/connect/Connect.svelte | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/routes/connect/Connect.svelte b/src/routes/connect/Connect.svelte index f679086..d78ce89 100644 --- a/src/routes/connect/Connect.svelte +++ b/src/routes/connect/Connect.svelte @@ -11,6 +11,7 @@ const parent = window.opener; const bridge = new Bridge(SimpleSignerPageType.CONNECT); + const redirect = bridge.getRedirectFromUrl(); $wallets = bridge.getWalletsFromUrl(); if (parent && !$wallets.length) { @@ -26,6 +27,11 @@ const publicKey: string = detail.publicKey; const wallet: IWallet = detail.wallet; bridge.sendOnConnectEvent(publicKey, wallet.getName()); + if (redirect) { + window.location.href = `/${redirect}`; + } else { + bridge.closeWindow(); + } } bridge.sendOnReadyEvent(); From e50f4e68dc6b3d898d563b05f2a9377cdfcb4880 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 8 Feb 2024 17:08:21 -0300 Subject: [PATCH 09/14] Add package-lock.json --- package-lock.json | 187 +++++++++++++++++++++------------------------- 1 file changed, 87 insertions(+), 100 deletions(-) diff --git a/package-lock.json b/package-lock.json index 43248c9..372ccf9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1739,14 +1739,6 @@ "sodium-native": "^4.0.1" } }, - "node_modules/@stellar/stellar-base/node_modules/bignumber.js": { - "version": "9.1.2", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", - "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==", - "engines": { - "node": "*" - } - }, "node_modules/@stellar/stellar-base/node_modules/buffer": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", @@ -1770,16 +1762,6 @@ "ieee754": "^1.2.1" } }, - "node_modules/@stellar/stellar-base/node_modules/sodium-native": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-4.0.4.tgz", - "integrity": "sha512-faqOKw4WQKK7r/ybn6Lqo1F9+L5T6NlBJJYvpxbZPetpWylUVqz449mvlwIBKBqxEHbWakWuOlUt8J3Qpc4sWw==", - "hasInstallScript": true, - "optional": true, - "dependencies": { - "node-gyp-build": "^4.6.0" - } - }, "node_modules/@sveltejs/vite-plugin-svelte": { "version": "1.0.0-next.44", "resolved": "https://registry.npmjs.org/@sveltejs/vite-plugin-svelte/-/vite-plugin-svelte-1.0.0-next.44.tgz", @@ -3155,6 +3137,34 @@ "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==", "dev": true }, + "node_modules/axios": { + "version": "1.6.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz", + "integrity": "sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==", + "dependencies": { + "follow-redirects": "^1.15.4", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/axios/node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/babel-jest": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-27.5.1.tgz", @@ -3304,6 +3314,14 @@ "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", "dev": true }, + "node_modules/bignumber.js": { + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", + "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==", + "engines": { + "node": "*" + } + }, "node_modules/binary-extensions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", @@ -9341,6 +9359,16 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/sodium-native": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-4.0.6.tgz", + "integrity": "sha512-uYsyycwcz9kYDwpXxJmL2YZosynsxcP6RPySbARVJdC9uNDa2CMjzJ7/WsMMvThKgvAYsBWdZc7L/WSVj9lTcA==", + "hasInstallScript": true, + "optional": true, + "dependencies": { + "node-gyp-build": "^4.6.0" + } + }, "node_modules/sonic-boom": { "version": "2.8.0", "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-2.8.0.tgz", @@ -9506,42 +9534,6 @@ "urijs": "^1.19.1" } }, - "node_modules/stellar-sdk/node_modules/axios": { - "version": "1.6.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.4.tgz", - "integrity": "sha512-heJnIs6N4aa1eSthhN9M5ioILu8Wi8vmQW9iHQ9NUvfkJb0lEEDUiIdQNAuBtfUt3FxReaKdpQA5DbmMOqzF/A==", - "dependencies": { - "follow-redirects": "^1.15.4", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, - "node_modules/stellar-sdk/node_modules/bignumber.js": { - "version": "9.1.2", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", - "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==", - "engines": { - "node": "*" - } - }, - "node_modules/stellar-sdk/node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/stellar-sdk/node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" - }, "node_modules/stream-shift": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.1.tgz", @@ -12076,11 +12068,6 @@ "tweetnacl": "^1.0.3" }, "dependencies": { - "bignumber.js": { - "version": "9.1.2", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", - "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==" - }, "buffer": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", @@ -12089,15 +12076,6 @@ "base64-js": "^1.3.1", "ieee754": "^1.2.1" } - }, - "sodium-native": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-4.0.4.tgz", - "integrity": "sha512-faqOKw4WQKK7r/ybn6Lqo1F9+L5T6NlBJJYvpxbZPetpWylUVqz449mvlwIBKBqxEHbWakWuOlUt8J3Qpc4sWw==", - "optional": true, - "requires": { - "node-gyp-build": "^4.6.0" - } } } }, @@ -13220,6 +13198,33 @@ "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==", "dev": true }, + "axios": { + "version": "1.6.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz", + "integrity": "sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==", + "requires": { + "follow-redirects": "^1.15.4", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + }, + "dependencies": { + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + } + } + }, "babel-jest": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-27.5.1.tgz", @@ -13330,6 +13335,11 @@ } } }, + "bignumber.js": { + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", + "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==" + }, "binary-extensions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", @@ -17754,6 +17764,15 @@ } } }, + "sodium-native": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-4.0.6.tgz", + "integrity": "sha512-uYsyycwcz9kYDwpXxJmL2YZosynsxcP6RPySbARVJdC9uNDa2CMjzJ7/WsMMvThKgvAYsBWdZc7L/WSVj9lTcA==", + "optional": true, + "requires": { + "node-gyp-build": "^4.6.0" + } + }, "sonic-boom": { "version": "2.8.0", "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-2.8.0.tgz", @@ -17890,38 +17909,6 @@ "randombytes": "^2.1.0", "toml": "^3.0.0", "urijs": "^1.19.1" - }, - "dependencies": { - "axios": { - "version": "1.6.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.4.tgz", - "integrity": "sha512-heJnIs6N4aa1eSthhN9M5ioILu8Wi8vmQW9iHQ9NUvfkJb0lEEDUiIdQNAuBtfUt3FxReaKdpQA5DbmMOqzF/A==", - "requires": { - "follow-redirects": "^1.15.4", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, - "bignumber.js": { - "version": "9.1.2", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", - "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==" - }, - "form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - } - }, - "proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" - } } }, "stream-shift": { From 579778d518f9c9181bd7f6fdb0eeb0a4f9f6f39a Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 8 Feb 2024 17:25:20 -0300 Subject: [PATCH 10/14] Change simpleSignerURL in test.html --- test.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test.html b/test.html index fe2b8f1..ce5c5ee 100644 --- a/test.html +++ b/test.html @@ -19,8 +19,7 @@