@depay/widgets 6.0.1 → 6.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1276,6 +1276,83 @@ DePayWidgets.Connect().then(()=>{}).catch((error)=>{
1276
1276
 
1277
1277
  ```
1278
1278
 
1279
+ ## DePay Login
1280
+
1281
+ DePay Login allows you to perform web3 wallet logins with ease.
1282
+
1283
+ Returns `account` if succesfully signed and recovered log in message.
1284
+
1285
+ ```
1286
+ <script src="https://integrate.depay.fi/widgets/v6.js"/>
1287
+ ```
1288
+
1289
+ ```javascript
1290
+ let message = "Sign to login"
1291
+ let account = await DePayWidgets.Login({ message })
1292
+ ```
1293
+
1294
+ Connects wallet and instructs connected wallet to sign `message`, afterwards sends `signature` and `message` to `POST /login` (or `endpoint` if defined):
1295
+
1296
+ ```
1297
+ POST /login
1298
+ BODY
1299
+ {
1300
+ "message": "Sign to login",
1301
+ "signature": "0x123456" // raw signature
1302
+ }
1303
+ ```
1304
+
1305
+ The `/login` endpoint needs to recover the address for `message` and `signature` and needs to return it in the response:
1306
+
1307
+ ```
1308
+ POST /login
1309
+ RESPONSE
1310
+ "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
1311
+ ```
1312
+
1313
+ Which will resolve the `DePayWidgets.Login` request to the resolved account:
1314
+
1315
+ ```javascript
1316
+ account // 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
1317
+ ```
1318
+
1319
+ You can also pass a `recover` function that takes care of signature recovery:
1320
+
1321
+ ```javascript
1322
+ DePayWidgets.Login({ message, recover: ({ message, signature })=>{
1323
+ return new Promise((resolve, reject)=>{
1324
+ fetch('https://example.com/login', {
1325
+ method: 'POST',
1326
+ body: JSON.stringify({ message, signature })
1327
+ })
1328
+ .then((response)=>{
1329
+ if(response.status == 200) {
1330
+ response.text().then((account)=>{
1331
+ resolve(account)
1332
+ }).catch(reject)
1333
+ } else {
1334
+ response.text().then((text)=>{
1335
+ reject(text || 'Recovering login signature failed!')
1336
+ }).catch(reject)
1337
+ }
1338
+ })
1339
+ })
1340
+ }
1341
+ })
1342
+ ```
1343
+
1344
+ ### Rejections
1345
+
1346
+ 1. Rejects if user just closes the dialog without connecting any wallet:
1347
+
1348
+ ```javascript
1349
+
1350
+ DePayWidgets.Login().then(()=>{}).catch((error)=>{
1351
+ error // "USER_CLOSED_DIALOG"
1352
+ })
1353
+
1354
+ ```
1355
+
1279
1356
  ## Development
1280
1357
 
1281
1358
  ### Quick start