@dynamic-labs/flow 0.17.0-RC.11
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/CHANGELOG.md +800 -0
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/_virtual/_tslib.cjs +30 -0
- package/_virtual/_tslib.js +26 -0
- package/package.json +34 -0
- package/src/FlowWalletConnector.cjs +162 -0
- package/src/FlowWalletConnector.d.ts +29 -0
- package/src/FlowWalletConnector.js +157 -0
- package/src/blocto.cjs +22 -0
- package/src/blocto.d.ts +7 -0
- package/src/blocto.js +20 -0
- package/src/dapper.cjs +22 -0
- package/src/dapper.d.ts +7 -0
- package/src/dapper.js +20 -0
- package/src/index.cjs +14 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +9 -0
- package/src/lilico.cjs +42 -0
- package/src/lilico.d.ts +9 -0
- package/src/lilico.js +40 -0
- package/src/types.d.ts +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Dynamic Labs, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/******************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation.
|
|
7
|
+
|
|
8
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
+
purpose with or without fee is hereby granted.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
+
***************************************************************************** */
|
|
19
|
+
|
|
20
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
21
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
22
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
23
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
24
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
25
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
26
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.__awaiter = __awaiter;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
|
|
16
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { __awaiter };
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dynamic-labs/flow",
|
|
3
|
+
"version": "0.17.0-RC.11",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
7
|
+
"directory": "packages/flow"
|
|
8
|
+
},
|
|
9
|
+
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/dynamic-labs/DynamicAuth/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/dynamic-labs/DynamicAuth#readme",
|
|
14
|
+
"author": "Dynamic Labs, Inc.",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"main": "./src/index.cjs",
|
|
17
|
+
"module": "./src/index.js",
|
|
18
|
+
"types": "./src/index.d.ts",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./src/index.d.ts",
|
|
23
|
+
"import": "./src/index.js",
|
|
24
|
+
"require": "./src/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@onflow/fcl": "^1.3.2",
|
|
30
|
+
"@dynamic-labs/utils": "0.17.0-RC.11",
|
|
31
|
+
"@dynamic-labs/wallet-connector-core": "0.17.0-RC.11"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {}
|
|
34
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
6
|
+
var fcl = require('@onflow/fcl');
|
|
7
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
var utils = require('@dynamic-labs/utils');
|
|
9
|
+
|
|
10
|
+
const get = (key) => {
|
|
11
|
+
if (typeof window === 'undefined') {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const value = window.localStorage.getItem(key);
|
|
15
|
+
try {
|
|
16
|
+
if (value) {
|
|
17
|
+
return JSON.parse(value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
walletConnectorCore.logger.error(e);
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
};
|
|
25
|
+
const set = (key, value) => {
|
|
26
|
+
if (typeof window !== 'undefined') {
|
|
27
|
+
window.localStorage.setItem(key, JSON.stringify(value));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const LOCAL_STORAGE = {
|
|
31
|
+
can: true,
|
|
32
|
+
get: (key) => _tslib.__awaiter(void 0, void 0, void 0, function* () { return get(key); }),
|
|
33
|
+
put: (key, value) => _tslib.__awaiter(void 0, void 0, void 0, function* () { return set(key, value); }),
|
|
34
|
+
};
|
|
35
|
+
class FlowWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
36
|
+
constructor({ appName, appLogoUrl, }) {
|
|
37
|
+
super();
|
|
38
|
+
this.connectedChain = 'FLOW';
|
|
39
|
+
this.supportedChains = ['FLOW'];
|
|
40
|
+
this.appName = appName;
|
|
41
|
+
this.appLogoUrl = appLogoUrl;
|
|
42
|
+
}
|
|
43
|
+
connect() {
|
|
44
|
+
var _a;
|
|
45
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
this.setupConfig();
|
|
47
|
+
const { addr } = yield fcl.currentUser().authenticate();
|
|
48
|
+
if (addr) {
|
|
49
|
+
yield ((_a = this.onAccountChange) === null || _a === void 0 ? void 0 : _a.call(this, [addr]));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
setupEventListeners(listeners) {
|
|
54
|
+
this.onAccountChange = listeners.onAccountChange;
|
|
55
|
+
}
|
|
56
|
+
setupConfig() {
|
|
57
|
+
this.baseConfig();
|
|
58
|
+
}
|
|
59
|
+
baseConfig() {
|
|
60
|
+
fcl.config()
|
|
61
|
+
.put('app.detail.title', this.appName)
|
|
62
|
+
.put('app.detail.icon', this.appLogoUrl)
|
|
63
|
+
.put('accessNode.api', 'https://rest-mainnet.onflow.org')
|
|
64
|
+
.put('flow.network', 'mainnet')
|
|
65
|
+
.put('fcl.storage', LOCAL_STORAGE);
|
|
66
|
+
}
|
|
67
|
+
fetchPublicAddress() {
|
|
68
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
try {
|
|
70
|
+
yield this.connect();
|
|
71
|
+
const user = yield fcl.currentUser().snapshot();
|
|
72
|
+
return user.addr;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
walletConnectorCore.logger.error(error);
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
proveOwnership(messageToSign) {
|
|
81
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
try {
|
|
83
|
+
yield this.connect();
|
|
84
|
+
yield this.signDelay();
|
|
85
|
+
const signedMessage = yield this.signMessage(messageToSign);
|
|
86
|
+
if (!signedMessage) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
const data = {
|
|
90
|
+
appName: this.appName,
|
|
91
|
+
signedMessage: JSON.parse(signedMessage),
|
|
92
|
+
};
|
|
93
|
+
return JSON.stringify(data);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
walletConnectorCore.logger.error(error);
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
signMessage(messageToSign) {
|
|
102
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const message = Buffer.from(messageToSign).toString('hex');
|
|
104
|
+
const signedMessage = yield fcl.currentUser().signUserMessage(message);
|
|
105
|
+
if (signedMessage.includes('Declined')) {
|
|
106
|
+
throw new utils.DynamicError('User declined the signature');
|
|
107
|
+
}
|
|
108
|
+
return JSON.stringify(signedMessage);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
getBalance() {
|
|
112
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
this.baseConfig();
|
|
114
|
+
const address = yield this.fetchPublicAddress();
|
|
115
|
+
if (address) {
|
|
116
|
+
const code = `
|
|
117
|
+
pub fun main(): UFix64 {
|
|
118
|
+
let account = getAccount(${address});
|
|
119
|
+
return account.balance;
|
|
120
|
+
}
|
|
121
|
+
`;
|
|
122
|
+
try {
|
|
123
|
+
return yield fcl.send([fcl.script(code)]).then(fcl.decode);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
walletConnectorCore.logger.error(error);
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
endSession() {
|
|
136
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
fcl.currentUser().unauthenticate();
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
switchNetwork() {
|
|
141
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
throw new utils.DynamicError('Not supported');
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
getConnectedAccounts() {
|
|
146
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const user = yield fcl.currentUser().snapshot();
|
|
148
|
+
if (user.addr) {
|
|
149
|
+
return [user.addr];
|
|
150
|
+
}
|
|
151
|
+
return [];
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
signDelay() {
|
|
155
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
return Promise.resolve();
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
exports.FlowWalletConnector = FlowWalletConnector;
|
|
162
|
+
exports.LOCAL_STORAGE = LOCAL_STORAGE;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Chain, WalletConnectorBase, WalletEventListeners } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
export declare const LOCAL_STORAGE: {
|
|
3
|
+
can: boolean;
|
|
4
|
+
get: (key: string) => Promise<any>;
|
|
5
|
+
put: (key: string, value: any) => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare abstract class FlowWalletConnector extends WalletConnectorBase {
|
|
8
|
+
protected appName?: string;
|
|
9
|
+
protected appLogoUrl?: string;
|
|
10
|
+
protected onAccountChange?: (address: string[]) => Promise<void>;
|
|
11
|
+
connectedChain: Chain;
|
|
12
|
+
supportedChains: Chain[];
|
|
13
|
+
constructor({ appName, appLogoUrl, }: {
|
|
14
|
+
appLogoUrl?: string;
|
|
15
|
+
appName?: string;
|
|
16
|
+
});
|
|
17
|
+
connect(): Promise<void>;
|
|
18
|
+
setupEventListeners(listeners: WalletEventListeners): void;
|
|
19
|
+
setupConfig(): void;
|
|
20
|
+
baseConfig(): void;
|
|
21
|
+
fetchPublicAddress(): Promise<string | undefined>;
|
|
22
|
+
proveOwnership(messageToSign: string): Promise<string | undefined>;
|
|
23
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
24
|
+
getBalance(): Promise<string | undefined>;
|
|
25
|
+
endSession(): Promise<void>;
|
|
26
|
+
switchNetwork(): Promise<void>;
|
|
27
|
+
getConnectedAccounts(): Promise<string[]>;
|
|
28
|
+
signDelay(): Promise<void>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
+
import { config, currentUser, send, script, decode } from '@onflow/fcl';
|
|
3
|
+
import { WalletConnectorBase, logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
5
|
+
|
|
6
|
+
const get = (key) => {
|
|
7
|
+
if (typeof window === 'undefined') {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
const value = window.localStorage.getItem(key);
|
|
11
|
+
try {
|
|
12
|
+
if (value) {
|
|
13
|
+
return JSON.parse(value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
logger.error(e);
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
};
|
|
21
|
+
const set = (key, value) => {
|
|
22
|
+
if (typeof window !== 'undefined') {
|
|
23
|
+
window.localStorage.setItem(key, JSON.stringify(value));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const LOCAL_STORAGE = {
|
|
27
|
+
can: true,
|
|
28
|
+
get: (key) => __awaiter(void 0, void 0, void 0, function* () { return get(key); }),
|
|
29
|
+
put: (key, value) => __awaiter(void 0, void 0, void 0, function* () { return set(key, value); }),
|
|
30
|
+
};
|
|
31
|
+
class FlowWalletConnector extends WalletConnectorBase {
|
|
32
|
+
constructor({ appName, appLogoUrl, }) {
|
|
33
|
+
super();
|
|
34
|
+
this.connectedChain = 'FLOW';
|
|
35
|
+
this.supportedChains = ['FLOW'];
|
|
36
|
+
this.appName = appName;
|
|
37
|
+
this.appLogoUrl = appLogoUrl;
|
|
38
|
+
}
|
|
39
|
+
connect() {
|
|
40
|
+
var _a;
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
this.setupConfig();
|
|
43
|
+
const { addr } = yield currentUser().authenticate();
|
|
44
|
+
if (addr) {
|
|
45
|
+
yield ((_a = this.onAccountChange) === null || _a === void 0 ? void 0 : _a.call(this, [addr]));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
setupEventListeners(listeners) {
|
|
50
|
+
this.onAccountChange = listeners.onAccountChange;
|
|
51
|
+
}
|
|
52
|
+
setupConfig() {
|
|
53
|
+
this.baseConfig();
|
|
54
|
+
}
|
|
55
|
+
baseConfig() {
|
|
56
|
+
config()
|
|
57
|
+
.put('app.detail.title', this.appName)
|
|
58
|
+
.put('app.detail.icon', this.appLogoUrl)
|
|
59
|
+
.put('accessNode.api', 'https://rest-mainnet.onflow.org')
|
|
60
|
+
.put('flow.network', 'mainnet')
|
|
61
|
+
.put('fcl.storage', LOCAL_STORAGE);
|
|
62
|
+
}
|
|
63
|
+
fetchPublicAddress() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
try {
|
|
66
|
+
yield this.connect();
|
|
67
|
+
const user = yield currentUser().snapshot();
|
|
68
|
+
return user.addr;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
logger.error(error);
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
proveOwnership(messageToSign) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
try {
|
|
79
|
+
yield this.connect();
|
|
80
|
+
yield this.signDelay();
|
|
81
|
+
const signedMessage = yield this.signMessage(messageToSign);
|
|
82
|
+
if (!signedMessage) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
const data = {
|
|
86
|
+
appName: this.appName,
|
|
87
|
+
signedMessage: JSON.parse(signedMessage),
|
|
88
|
+
};
|
|
89
|
+
return JSON.stringify(data);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
logger.error(error);
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
signMessage(messageToSign) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const message = Buffer.from(messageToSign).toString('hex');
|
|
100
|
+
const signedMessage = yield currentUser().signUserMessage(message);
|
|
101
|
+
if (signedMessage.includes('Declined')) {
|
|
102
|
+
throw new DynamicError('User declined the signature');
|
|
103
|
+
}
|
|
104
|
+
return JSON.stringify(signedMessage);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
getBalance() {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
this.baseConfig();
|
|
110
|
+
const address = yield this.fetchPublicAddress();
|
|
111
|
+
if (address) {
|
|
112
|
+
const code = `
|
|
113
|
+
pub fun main(): UFix64 {
|
|
114
|
+
let account = getAccount(${address});
|
|
115
|
+
return account.balance;
|
|
116
|
+
}
|
|
117
|
+
`;
|
|
118
|
+
try {
|
|
119
|
+
return yield send([script(code)]).then(decode);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
logger.error(error);
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
endSession() {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
currentUser().unauthenticate();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
switchNetwork() {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
throw new DynamicError('Not supported');
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
getConnectedAccounts() {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
const user = yield currentUser().snapshot();
|
|
144
|
+
if (user.addr) {
|
|
145
|
+
return [user.addr];
|
|
146
|
+
}
|
|
147
|
+
return [];
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
signDelay() {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
return Promise.resolve();
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export { FlowWalletConnector, LOCAL_STORAGE };
|
package/src/blocto.cjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fcl = require('@onflow/fcl');
|
|
4
|
+
var FlowWalletConnector = require('./FlowWalletConnector.cjs');
|
|
5
|
+
|
|
6
|
+
class Blocto extends FlowWalletConnector.FlowWalletConnector {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.name = 'Blocto';
|
|
10
|
+
this.canConnectViaCustodialService = true;
|
|
11
|
+
}
|
|
12
|
+
setupConfig() {
|
|
13
|
+
super.setupConfig();
|
|
14
|
+
fcl.config()
|
|
15
|
+
.put('challenge.scope', 'email')
|
|
16
|
+
.put('discovery.wallet', 'https://flow-wallet.blocto.app/authn')
|
|
17
|
+
.put('service.OpenID.scopes', 'email!')
|
|
18
|
+
.put('discovery.wallet.method', undefined);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = Blocto;
|
package/src/blocto.d.ts
ADDED
package/src/blocto.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { config } from '@onflow/fcl';
|
|
2
|
+
import { FlowWalletConnector } from './FlowWalletConnector.js';
|
|
3
|
+
|
|
4
|
+
class Blocto extends FlowWalletConnector {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.name = 'Blocto';
|
|
8
|
+
this.canConnectViaCustodialService = true;
|
|
9
|
+
}
|
|
10
|
+
setupConfig() {
|
|
11
|
+
super.setupConfig();
|
|
12
|
+
config()
|
|
13
|
+
.put('challenge.scope', 'email')
|
|
14
|
+
.put('discovery.wallet', 'https://flow-wallet.blocto.app/authn')
|
|
15
|
+
.put('service.OpenID.scopes', 'email!')
|
|
16
|
+
.put('discovery.wallet.method', undefined);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { Blocto as default };
|
package/src/dapper.cjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fcl = require('@onflow/fcl');
|
|
4
|
+
var FlowWalletConnector = require('./FlowWalletConnector.cjs');
|
|
5
|
+
|
|
6
|
+
class Dapper extends FlowWalletConnector.FlowWalletConnector {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.name = 'Dapper';
|
|
10
|
+
this.canConnectViaCustodialService = true;
|
|
11
|
+
}
|
|
12
|
+
setupConfig() {
|
|
13
|
+
super.setupConfig();
|
|
14
|
+
fcl.config()
|
|
15
|
+
.put('challenge.scope', undefined)
|
|
16
|
+
.put('discovery.wallet', 'https://accounts.meetdapper.com/fcl/authn-restricted')
|
|
17
|
+
.put('service.OpenID.scopes', undefined)
|
|
18
|
+
.put('discovery.wallet.method', 'POP/RPC');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = Dapper;
|
package/src/dapper.d.ts
ADDED
package/src/dapper.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { config } from '@onflow/fcl';
|
|
2
|
+
import { FlowWalletConnector } from './FlowWalletConnector.js';
|
|
3
|
+
|
|
4
|
+
class Dapper extends FlowWalletConnector {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.name = 'Dapper';
|
|
8
|
+
this.canConnectViaCustodialService = true;
|
|
9
|
+
}
|
|
10
|
+
setupConfig() {
|
|
11
|
+
super.setupConfig();
|
|
12
|
+
config()
|
|
13
|
+
.put('challenge.scope', undefined)
|
|
14
|
+
.put('discovery.wallet', 'https://accounts.meetdapper.com/fcl/authn-restricted')
|
|
15
|
+
.put('service.OpenID.scopes', undefined)
|
|
16
|
+
.put('discovery.wallet.method', 'POP/RPC');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { Dapper as default };
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var blocto = require('./blocto.cjs');
|
|
6
|
+
var dapper = require('./dapper.cjs');
|
|
7
|
+
var lilico = require('./lilico.cjs');
|
|
8
|
+
var FlowWalletConnector = require('./FlowWalletConnector.cjs');
|
|
9
|
+
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
11
|
+
const FlowWalletConnectors = (props) => [blocto, dapper, lilico];
|
|
12
|
+
|
|
13
|
+
exports.FlowWalletConnector = FlowWalletConnector.FlowWalletConnector;
|
|
14
|
+
exports.FlowWalletConnectors = FlowWalletConnectors;
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Blocto from './blocto.js';
|
|
2
|
+
import Dapper from './dapper.js';
|
|
3
|
+
import Lilico from './lilico.js';
|
|
4
|
+
export { FlowWalletConnector } from './FlowWalletConnector.js';
|
|
5
|
+
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
7
|
+
const FlowWalletConnectors = (props) => [Blocto, Dapper, Lilico];
|
|
8
|
+
|
|
9
|
+
export { FlowWalletConnectors };
|
package/src/lilico.cjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
4
|
+
var fcl = require('@onflow/fcl');
|
|
5
|
+
var utils = require('@dynamic-labs/utils');
|
|
6
|
+
var FlowWalletConnector = require('./FlowWalletConnector.cjs');
|
|
7
|
+
|
|
8
|
+
class Lilico extends FlowWalletConnector.FlowWalletConnector {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.name = 'Lilico';
|
|
12
|
+
}
|
|
13
|
+
setupConfig() {
|
|
14
|
+
super.setupConfig();
|
|
15
|
+
fcl.config()
|
|
16
|
+
.put('challenge.scope', undefined)
|
|
17
|
+
.put('discovery.wallet', 'chrome-extension://hpclkefagolihohboafpheddmmgdffjm/popup.html')
|
|
18
|
+
.put('service.OpenID.scopes', undefined)
|
|
19
|
+
.put('discovery.wallet.method', 'EXT/RPC');
|
|
20
|
+
}
|
|
21
|
+
isInstalledOnBrowser() {
|
|
22
|
+
var _a;
|
|
23
|
+
if (typeof window === 'undefined') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return Boolean((_a = window.fcl_extensions) === null || _a === void 0 ? void 0 : _a.some((ext) => ext.id === 'hpclkefagolihohboafpheddmmgdffjm'));
|
|
27
|
+
}
|
|
28
|
+
signDelay() {
|
|
29
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
if (utils.isMobile()) {
|
|
31
|
+
return Promise.resolve();
|
|
32
|
+
}
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
setTimeout(() => {
|
|
35
|
+
resolve();
|
|
36
|
+
}, 500);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = Lilico;
|
package/src/lilico.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FlowWalletConnector } from './FlowWalletConnector';
|
|
2
|
+
import './types';
|
|
3
|
+
declare class Lilico extends FlowWalletConnector {
|
|
4
|
+
name: string;
|
|
5
|
+
setupConfig(): void;
|
|
6
|
+
isInstalledOnBrowser(): boolean;
|
|
7
|
+
signDelay(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export default Lilico;
|