@onekeyfe/onekey-stellar-provider 2.2.56-alpha.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/LICENSE.md ADDED
@@ -0,0 +1,51 @@
1
+ # ONEKEY STANDARD SOURCE LICENSE (O-SSL)
2
+
3
+ This license governs use of the accompanying software. If you use the software,
4
+ you accept this license. If you do not accept the license, do not use the
5
+ software.
6
+
7
+ ## 1. Definitions
8
+
9
+ The terms "reproduce," "reproduction" and "distribution" have the same meaning
10
+ here as under Hong Kong copyright law.
11
+
12
+ "You" means the licensee of the software.
13
+
14
+ "Your company" means the company you worked for when you downloaded the
15
+ software.
16
+
17
+ "Reference use" means use of the software within your company as a reference,
18
+ in read only form, for the sole purposes of debugging your products,
19
+ maintaining your products, or enhancing the interoperability of your products
20
+ with the software, and specifically excludes the right to distribute the
21
+ software outside of your company.
22
+
23
+ "Licensed patents" means any Licensor patent claims which read directly on the
24
+ software as distributed by the Licensor under this license.
25
+
26
+ ## 2. Grant of Rights
27
+
28
+ (A) Copyright Grant - Subject to the terms of this license, the Licensor grants
29
+ you a non-transferable, non-exclusive, worldwide, royalty-free copyright
30
+ license to reproduce the software for reference use.
31
+
32
+ (B) Patent Grant - Subject to the terms of this license, the Licensor grants
33
+ you a non-transferable, non-exclusive, worldwide, royalty-free patent license
34
+ under licensed patents for reference use.
35
+
36
+ ## 3. Limitations
37
+
38
+ (A) No Trademark License - This license does not grant you any rights to use
39
+ the Licensor's name, logo, or trademarks.
40
+
41
+ (B) If you begin patent litigation against the Licensor over patents that you
42
+ think may apply to the software (including a cross-claim or counterclaim in
43
+ a lawsuit), your license to the software ends automatically.
44
+
45
+ (C) The software is licensed "as-is." You bear the risk of using it. The
46
+ Licensor gives no express warranties, guarantees or conditions. You may have
47
+ additional consumer rights under your local laws which this license cannot
48
+ change. To the extent permitted under your local laws, the Licensor excludes
49
+ the implied warranties of merchantability, fitness for a particular purpose and
50
+ non-infringement.This license agreement is governed by the laws of Hong Kong,
51
+ and any disputes related to this license agreement shall be resolved in accordance with Hong Kong law.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # cross-inpage-provider
@@ -0,0 +1,158 @@
1
+ import type { IInpageProviderConfig } from '@onekeyfe/cross-inpage-provider-core';
2
+ import { ProviderStellarBase } from './ProviderStellarBase';
3
+ import type { IJsonRpcRequest } from '@onekeyfe/cross-inpage-provider-types';
4
+ export declare enum PROVIDER_EVENTS {
5
+ accountsChanged = "accountsChanged",
6
+ disconnect = "disconnect",
7
+ message_low_level = "message_low_level"
8
+ }
9
+ type StellarProviderEventsMap = {
10
+ [PROVIDER_EVENTS.accountsChanged]: (address: string | null) => void;
11
+ [PROVIDER_EVENTS.disconnect]: () => void;
12
+ [PROVIDER_EVENTS.message_low_level]: (payload: IJsonRpcRequest) => void;
13
+ };
14
+ export declare enum StellarRequestMethods {
15
+ stellar_getAddress = "stellar_getAddress",
16
+ stellar_signTransaction = "stellar_signTransaction",
17
+ stellar_signAuthEntry = "stellar_signAuthEntry",
18
+ stellar_signMessage = "stellar_signMessage",
19
+ stellar_getNetwork = "stellar_getNetwork",
20
+ stellar_disconnect = "stellar_disconnect"
21
+ }
22
+ export type GetAddressParams = {
23
+ path?: string;
24
+ skipRequestAccess?: boolean;
25
+ };
26
+ export type GetAddressResult = {
27
+ address: string;
28
+ };
29
+ export type SignTransactionParams = {
30
+ xdr: string;
31
+ networkPassphrase?: string;
32
+ address?: string;
33
+ path?: string;
34
+ submit?: boolean;
35
+ submitUrl?: string;
36
+ };
37
+ export type SignTransactionResult = {
38
+ signedTxXdr: string;
39
+ signerAddress?: string;
40
+ };
41
+ export type SignAuthEntryParams = {
42
+ authEntry: string;
43
+ networkPassphrase?: string;
44
+ address?: string;
45
+ path?: string;
46
+ };
47
+ export type SignAuthEntryResult = {
48
+ signedAuthEntry: string;
49
+ signerAddress?: string;
50
+ };
51
+ export type SignMessageParams = {
52
+ message: string;
53
+ networkPassphrase?: string;
54
+ address?: string;
55
+ path?: string;
56
+ };
57
+ export type SignMessageResult = {
58
+ signedMessage: string;
59
+ signerAddress?: string;
60
+ };
61
+ export type GetNetworkResult = {
62
+ network: string;
63
+ networkPassphrase: string;
64
+ };
65
+ export interface IProviderStellar extends ProviderStellarBase {
66
+ /**
67
+ * Get the public key from the active account or specific path
68
+ */
69
+ getAddress(params?: GetAddressParams): Promise<GetAddressResult>;
70
+ /**
71
+ * Sign a transaction in XDR format
72
+ */
73
+ signTransaction(xdr: string, opts?: {
74
+ networkPassphrase?: string;
75
+ address?: string;
76
+ path?: string;
77
+ submit?: boolean;
78
+ submitUrl?: string;
79
+ }): Promise<SignTransactionResult>;
80
+ /**
81
+ * Sign an AuthEntry XDR
82
+ */
83
+ signAuthEntry(authEntry: string, opts?: {
84
+ networkPassphrase?: string;
85
+ address?: string;
86
+ path?: string;
87
+ }): Promise<SignAuthEntryResult>;
88
+ /**
89
+ * Sign an arbitrary message
90
+ */
91
+ signMessage(message: string, opts?: {
92
+ networkPassphrase?: string;
93
+ address?: string;
94
+ path?: string;
95
+ }): Promise<SignMessageResult>;
96
+ /**
97
+ * Get the current selected network
98
+ */
99
+ getNetwork(): Promise<GetNetworkResult>;
100
+ /**
101
+ * Disconnect from the wallet
102
+ */
103
+ disconnect(): Promise<void>;
104
+ }
105
+ export type OneKeyStellarProviderProps = IInpageProviderConfig & {
106
+ timeout?: number;
107
+ };
108
+ export declare class ProviderStellar extends ProviderStellarBase implements IProviderStellar {
109
+ private _address?;
110
+ constructor(props: OneKeyStellarProviderProps);
111
+ private _registerEvents;
112
+ private _callBridge;
113
+ private _handleDisconnected;
114
+ isAccountsChanged(address: string | undefined): boolean;
115
+ private _handleAccountChange;
116
+ on<E extends keyof StellarProviderEventsMap>(event: E, listener: StellarProviderEventsMap[E]): this;
117
+ emit<E extends keyof StellarProviderEventsMap>(event: E, ...args: Parameters<StellarProviderEventsMap[E]>): boolean;
118
+ removeListener<E extends keyof StellarProviderEventsMap>(eventName: E, listener: StellarProviderEventsMap[E]): this;
119
+ /**
120
+ * Get the address from the wallet
121
+ */
122
+ getAddress(params?: GetAddressParams): Promise<GetAddressResult>;
123
+ /**
124
+ * Sign a transaction
125
+ */
126
+ signTransaction(xdr: string, opts?: {
127
+ networkPassphrase?: string;
128
+ address?: string;
129
+ path?: string;
130
+ submit?: boolean;
131
+ submitUrl?: string;
132
+ }): Promise<SignTransactionResult>;
133
+ /**
134
+ * Sign an AuthEntry
135
+ */
136
+ signAuthEntry(authEntry: string, opts?: {
137
+ networkPassphrase?: string;
138
+ address?: string;
139
+ path?: string;
140
+ }): Promise<SignAuthEntryResult>;
141
+ /**
142
+ * Sign a message
143
+ */
144
+ signMessage(message: string, opts?: {
145
+ networkPassphrase?: string;
146
+ address?: string;
147
+ path?: string;
148
+ }): Promise<SignMessageResult>;
149
+ /**
150
+ * Get the current network
151
+ */
152
+ getNetwork(): Promise<GetNetworkResult>;
153
+ /**
154
+ * Disconnect from the wallet
155
+ */
156
+ disconnect(): Promise<void>;
157
+ }
158
+ export {};
@@ -0,0 +1,163 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getOrCreateExtInjectedJsBridge } from '@onekeyfe/extension-bridge-injected';
11
+ import { ProviderStellarBase } from './ProviderStellarBase';
12
+ export var PROVIDER_EVENTS;
13
+ (function (PROVIDER_EVENTS) {
14
+ PROVIDER_EVENTS["accountsChanged"] = "accountsChanged";
15
+ PROVIDER_EVENTS["disconnect"] = "disconnect";
16
+ PROVIDER_EVENTS["message_low_level"] = "message_low_level";
17
+ })(PROVIDER_EVENTS || (PROVIDER_EVENTS = {}));
18
+ // Stellar request method names
19
+ export var StellarRequestMethods;
20
+ (function (StellarRequestMethods) {
21
+ StellarRequestMethods["stellar_getAddress"] = "stellar_getAddress";
22
+ StellarRequestMethods["stellar_signTransaction"] = "stellar_signTransaction";
23
+ StellarRequestMethods["stellar_signAuthEntry"] = "stellar_signAuthEntry";
24
+ StellarRequestMethods["stellar_signMessage"] = "stellar_signMessage";
25
+ StellarRequestMethods["stellar_getNetwork"] = "stellar_getNetwork";
26
+ StellarRequestMethods["stellar_disconnect"] = "stellar_disconnect";
27
+ })(StellarRequestMethods || (StellarRequestMethods = {}));
28
+ function isWalletEventMethodMatch({ method, name }) {
29
+ return method === `wallet_events_${name}`;
30
+ }
31
+ export class ProviderStellar extends ProviderStellarBase {
32
+ constructor(props) {
33
+ super(Object.assign(Object.assign({}, props), { bridge: props.bridge || getOrCreateExtInjectedJsBridge({ timeout: props.timeout }) }));
34
+ this._registerEvents();
35
+ }
36
+ _registerEvents() {
37
+ window.addEventListener('onekey_bridge_disconnect', () => {
38
+ this._handleDisconnected();
39
+ });
40
+ this.on(PROVIDER_EVENTS.message_low_level, (payload) => {
41
+ if (!payload)
42
+ return;
43
+ const { method, params } = payload;
44
+ if (isWalletEventMethodMatch({ method, name: PROVIDER_EVENTS.accountsChanged })) {
45
+ this._handleAccountChange(params);
46
+ }
47
+ });
48
+ }
49
+ _callBridge(params) {
50
+ return this.bridgeRequest(params);
51
+ }
52
+ _handleDisconnected(options = { emit: true }) {
53
+ this._address = undefined;
54
+ if (options.emit && this.isConnectionStatusChanged('disconnected')) {
55
+ this.connectionStatus = 'disconnected';
56
+ this.emit(PROVIDER_EVENTS.disconnect);
57
+ }
58
+ }
59
+ isAccountsChanged(address) {
60
+ if (!address)
61
+ return false;
62
+ if (!this._address)
63
+ return true;
64
+ return address !== this._address;
65
+ }
66
+ // trigger by bridge account change event
67
+ _handleAccountChange(payload) {
68
+ const address = payload;
69
+ if (this.isAccountsChanged(address)) {
70
+ this._address = address;
71
+ this.emit(PROVIDER_EVENTS.accountsChanged, address || null);
72
+ }
73
+ if (!address) {
74
+ this._handleDisconnected();
75
+ return;
76
+ }
77
+ }
78
+ on(event, listener) {
79
+ return super.on(event, listener);
80
+ }
81
+ emit(event, ...args) {
82
+ return super.emit(event, ...args);
83
+ }
84
+ removeListener(eventName, listener) {
85
+ return super.removeListener(eventName, listener);
86
+ }
87
+ /**
88
+ * Get the address from the wallet
89
+ */
90
+ getAddress(params) {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ const result = yield this._callBridge({
93
+ method: StellarRequestMethods.stellar_getAddress,
94
+ params,
95
+ });
96
+ // Store the address for account change tracking
97
+ if (result.address) {
98
+ this._address = result.address;
99
+ }
100
+ return result;
101
+ });
102
+ }
103
+ /**
104
+ * Sign a transaction
105
+ */
106
+ signTransaction(xdr, opts) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ const result = yield this._callBridge({
109
+ method: StellarRequestMethods.stellar_signTransaction,
110
+ params: Object.assign({ xdr }, opts),
111
+ });
112
+ return result;
113
+ });
114
+ }
115
+ /**
116
+ * Sign an AuthEntry
117
+ */
118
+ signAuthEntry(authEntry, opts) {
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ const result = yield this._callBridge({
121
+ method: StellarRequestMethods.stellar_signAuthEntry,
122
+ params: Object.assign({ authEntry }, opts),
123
+ });
124
+ return result;
125
+ });
126
+ }
127
+ /**
128
+ * Sign a message
129
+ */
130
+ signMessage(message, opts) {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ const result = yield this._callBridge({
133
+ method: StellarRequestMethods.stellar_signMessage,
134
+ params: Object.assign({ message }, opts),
135
+ });
136
+ return result;
137
+ });
138
+ }
139
+ /**
140
+ * Get the current network
141
+ */
142
+ getNetwork() {
143
+ return __awaiter(this, void 0, void 0, function* () {
144
+ const result = yield this._callBridge({
145
+ method: StellarRequestMethods.stellar_getNetwork,
146
+ params: void 0,
147
+ });
148
+ return result;
149
+ });
150
+ }
151
+ /**
152
+ * Disconnect from the wallet
153
+ */
154
+ disconnect() {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ yield this._callBridge({
157
+ method: StellarRequestMethods.stellar_disconnect,
158
+ params: void 0,
159
+ });
160
+ this._handleDisconnected();
161
+ });
162
+ }
163
+ }
@@ -0,0 +1,8 @@
1
+ import { IInjectedProviderNames } from '@onekeyfe/cross-inpage-provider-types';
2
+ import { ProviderBase, IInpageProviderConfig } from '@onekeyfe/cross-inpage-provider-core';
3
+ declare class ProviderStellarBase extends ProviderBase {
4
+ constructor(props: IInpageProviderConfig);
5
+ protected providerName: IInjectedProviderNames;
6
+ request(data: unknown): Promise<unknown>;
7
+ }
8
+ export { ProviderStellarBase };
@@ -0,0 +1,12 @@
1
+ import { IInjectedProviderNames } from '@onekeyfe/cross-inpage-provider-types';
2
+ import { ProviderBase } from '@onekeyfe/cross-inpage-provider-core';
3
+ class ProviderStellarBase extends ProviderBase {
4
+ constructor(props) {
5
+ super(props);
6
+ this.providerName = IInjectedProviderNames.stellar;
7
+ }
8
+ request(data) {
9
+ return this.bridgeRequest(data);
10
+ }
11
+ }
12
+ export { ProviderStellarBase };
@@ -0,0 +1,65 @@
1
+ import type { ProviderStellar } from './OnekeyStellarProvider';
2
+ export type SignTransactionProps = {
3
+ xdr: string;
4
+ accountToSign?: string;
5
+ networkPassphrase?: string;
6
+ };
7
+ export type SignBlobProps = {
8
+ blob: string;
9
+ accountToSign?: string;
10
+ };
11
+ export type SignAuthEntryProps = {
12
+ xdr: string;
13
+ accountToSign?: string;
14
+ };
15
+ export type SignMessageProps = {
16
+ message: string;
17
+ accountToSign?: string;
18
+ };
19
+ /**
20
+ * Hana Wallet compatible wrapper for ProviderStellar
21
+ * Adapts OneKey Stellar Provider to match Hana wallet's interface
22
+ */
23
+ export declare class ProviderStellarHana {
24
+ private provider;
25
+ constructor(provider: ProviderStellar);
26
+ /**
27
+ * Get the public key of the current account
28
+ * @returns Promise<string> - The public key/address
29
+ */
30
+ getPublicKey(): Promise<string>;
31
+ /**
32
+ * Sign a transaction in XDR format
33
+ * @param params - Transaction signing parameters
34
+ * @returns Promise<string> - The signed transaction XDR
35
+ */
36
+ signTransaction({ xdr, accountToSign, networkPassphrase }: SignTransactionProps): Promise<string>;
37
+ /**
38
+ * Sign a blob (arbitrary data)
39
+ * Note: This is implemented using signMessage as ProviderStellar doesn't have a separate blob signing method
40
+ * @param params - Blob signing parameters
41
+ * @returns Promise<string> - The signed blob
42
+ */
43
+ signBlob({ blob, accountToSign }: SignBlobProps): Promise<string>;
44
+ /**
45
+ * Sign an AuthEntry in XDR format
46
+ * @param params - AuthEntry signing parameters
47
+ * @returns Promise<string> - The signed AuthEntry XDR
48
+ */
49
+ signAuthEntry({ xdr, accountToSign }: SignAuthEntryProps): Promise<string>;
50
+ /**
51
+ * Sign an arbitrary message
52
+ * @param params - Message signing parameters
53
+ * @returns Promise<string> - The signed message
54
+ */
55
+ signMessage({ message, accountToSign }: SignMessageProps): Promise<string>;
56
+ /**
57
+ * Get the current network configuration
58
+ * @returns Promise<{network: string, networkPassphrase: string}>
59
+ */
60
+ getNetwork(): Promise<import("./OnekeyStellarProvider").GetNetworkResult>;
61
+ /**
62
+ * Disconnect from the wallet
63
+ */
64
+ disconnect(): Promise<void>;
65
+ }
@@ -0,0 +1,99 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /**
11
+ * Hana Wallet compatible wrapper for ProviderStellar
12
+ * Adapts OneKey Stellar Provider to match Hana wallet's interface
13
+ */
14
+ export class ProviderStellarHana {
15
+ constructor(provider) {
16
+ this.provider = provider;
17
+ }
18
+ /**
19
+ * Get the public key of the current account
20
+ * @returns Promise<string> - The public key/address
21
+ */
22
+ getPublicKey() {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const result = yield this.provider.getAddress();
25
+ return result.address;
26
+ });
27
+ }
28
+ /**
29
+ * Sign a transaction in XDR format
30
+ * @param params - Transaction signing parameters
31
+ * @returns Promise<string> - The signed transaction XDR
32
+ */
33
+ signTransaction(_a) {
34
+ return __awaiter(this, arguments, void 0, function* ({ xdr, accountToSign, networkPassphrase }) {
35
+ const result = yield this.provider.signTransaction(xdr, {
36
+ address: accountToSign,
37
+ networkPassphrase,
38
+ });
39
+ return result.signedTxXdr;
40
+ });
41
+ }
42
+ /**
43
+ * Sign a blob (arbitrary data)
44
+ * Note: This is implemented using signMessage as ProviderStellar doesn't have a separate blob signing method
45
+ * @param params - Blob signing parameters
46
+ * @returns Promise<string> - The signed blob
47
+ */
48
+ signBlob(_a) {
49
+ return __awaiter(this, arguments, void 0, function* ({ blob, accountToSign }) {
50
+ const result = yield this.provider.signMessage(blob, {
51
+ address: accountToSign,
52
+ });
53
+ return result.signedMessage;
54
+ });
55
+ }
56
+ /**
57
+ * Sign an AuthEntry in XDR format
58
+ * @param params - AuthEntry signing parameters
59
+ * @returns Promise<string> - The signed AuthEntry XDR
60
+ */
61
+ signAuthEntry(_a) {
62
+ return __awaiter(this, arguments, void 0, function* ({ xdr, accountToSign }) {
63
+ const result = yield this.provider.signAuthEntry(xdr, {
64
+ address: accountToSign,
65
+ });
66
+ return result.signedAuthEntry;
67
+ });
68
+ }
69
+ /**
70
+ * Sign an arbitrary message
71
+ * @param params - Message signing parameters
72
+ * @returns Promise<string> - The signed message
73
+ */
74
+ signMessage(_a) {
75
+ return __awaiter(this, arguments, void 0, function* ({ message, accountToSign }) {
76
+ const result = yield this.provider.signMessage(message, {
77
+ address: accountToSign,
78
+ });
79
+ return result.signedMessage;
80
+ });
81
+ }
82
+ /**
83
+ * Get the current network configuration
84
+ * @returns Promise<{network: string, networkPassphrase: string}>
85
+ */
86
+ getNetwork() {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ return this.provider.getNetwork();
89
+ });
90
+ }
91
+ /**
92
+ * Disconnect from the wallet
93
+ */
94
+ disconnect() {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ return this.provider.disconnect();
97
+ });
98
+ }
99
+ }
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ProviderStellar = exports.StellarRequestMethods = exports.PROVIDER_EVENTS = void 0;
13
+ const extension_bridge_injected_1 = require("@onekeyfe/extension-bridge-injected");
14
+ const ProviderStellarBase_1 = require("./ProviderStellarBase");
15
+ var PROVIDER_EVENTS;
16
+ (function (PROVIDER_EVENTS) {
17
+ PROVIDER_EVENTS["accountsChanged"] = "accountsChanged";
18
+ PROVIDER_EVENTS["disconnect"] = "disconnect";
19
+ PROVIDER_EVENTS["message_low_level"] = "message_low_level";
20
+ })(PROVIDER_EVENTS || (exports.PROVIDER_EVENTS = PROVIDER_EVENTS = {}));
21
+ // Stellar request method names
22
+ var StellarRequestMethods;
23
+ (function (StellarRequestMethods) {
24
+ StellarRequestMethods["stellar_getAddress"] = "stellar_getAddress";
25
+ StellarRequestMethods["stellar_signTransaction"] = "stellar_signTransaction";
26
+ StellarRequestMethods["stellar_signAuthEntry"] = "stellar_signAuthEntry";
27
+ StellarRequestMethods["stellar_signMessage"] = "stellar_signMessage";
28
+ StellarRequestMethods["stellar_getNetwork"] = "stellar_getNetwork";
29
+ StellarRequestMethods["stellar_disconnect"] = "stellar_disconnect";
30
+ })(StellarRequestMethods || (exports.StellarRequestMethods = StellarRequestMethods = {}));
31
+ function isWalletEventMethodMatch({ method, name }) {
32
+ return method === `wallet_events_${name}`;
33
+ }
34
+ class ProviderStellar extends ProviderStellarBase_1.ProviderStellarBase {
35
+ constructor(props) {
36
+ super(Object.assign(Object.assign({}, props), { bridge: props.bridge || (0, extension_bridge_injected_1.getOrCreateExtInjectedJsBridge)({ timeout: props.timeout }) }));
37
+ this._registerEvents();
38
+ }
39
+ _registerEvents() {
40
+ window.addEventListener('onekey_bridge_disconnect', () => {
41
+ this._handleDisconnected();
42
+ });
43
+ this.on(PROVIDER_EVENTS.message_low_level, (payload) => {
44
+ if (!payload)
45
+ return;
46
+ const { method, params } = payload;
47
+ if (isWalletEventMethodMatch({ method, name: PROVIDER_EVENTS.accountsChanged })) {
48
+ this._handleAccountChange(params);
49
+ }
50
+ });
51
+ }
52
+ _callBridge(params) {
53
+ return this.bridgeRequest(params);
54
+ }
55
+ _handleDisconnected(options = { emit: true }) {
56
+ this._address = undefined;
57
+ if (options.emit && this.isConnectionStatusChanged('disconnected')) {
58
+ this.connectionStatus = 'disconnected';
59
+ this.emit(PROVIDER_EVENTS.disconnect);
60
+ }
61
+ }
62
+ isAccountsChanged(address) {
63
+ if (!address)
64
+ return false;
65
+ if (!this._address)
66
+ return true;
67
+ return address !== this._address;
68
+ }
69
+ // trigger by bridge account change event
70
+ _handleAccountChange(payload) {
71
+ const address = payload;
72
+ if (this.isAccountsChanged(address)) {
73
+ this._address = address;
74
+ this.emit(PROVIDER_EVENTS.accountsChanged, address || null);
75
+ }
76
+ if (!address) {
77
+ this._handleDisconnected();
78
+ return;
79
+ }
80
+ }
81
+ on(event, listener) {
82
+ return super.on(event, listener);
83
+ }
84
+ emit(event, ...args) {
85
+ return super.emit(event, ...args);
86
+ }
87
+ removeListener(eventName, listener) {
88
+ return super.removeListener(eventName, listener);
89
+ }
90
+ /**
91
+ * Get the address from the wallet
92
+ */
93
+ getAddress(params) {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ const result = yield this._callBridge({
96
+ method: StellarRequestMethods.stellar_getAddress,
97
+ params,
98
+ });
99
+ // Store the address for account change tracking
100
+ if (result.address) {
101
+ this._address = result.address;
102
+ }
103
+ return result;
104
+ });
105
+ }
106
+ /**
107
+ * Sign a transaction
108
+ */
109
+ signTransaction(xdr, opts) {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ const result = yield this._callBridge({
112
+ method: StellarRequestMethods.stellar_signTransaction,
113
+ params: Object.assign({ xdr }, opts),
114
+ });
115
+ return result;
116
+ });
117
+ }
118
+ /**
119
+ * Sign an AuthEntry
120
+ */
121
+ signAuthEntry(authEntry, opts) {
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ const result = yield this._callBridge({
124
+ method: StellarRequestMethods.stellar_signAuthEntry,
125
+ params: Object.assign({ authEntry }, opts),
126
+ });
127
+ return result;
128
+ });
129
+ }
130
+ /**
131
+ * Sign a message
132
+ */
133
+ signMessage(message, opts) {
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ const result = yield this._callBridge({
136
+ method: StellarRequestMethods.stellar_signMessage,
137
+ params: Object.assign({ message }, opts),
138
+ });
139
+ return result;
140
+ });
141
+ }
142
+ /**
143
+ * Get the current network
144
+ */
145
+ getNetwork() {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ const result = yield this._callBridge({
148
+ method: StellarRequestMethods.stellar_getNetwork,
149
+ params: void 0,
150
+ });
151
+ return result;
152
+ });
153
+ }
154
+ /**
155
+ * Disconnect from the wallet
156
+ */
157
+ disconnect() {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ yield this._callBridge({
160
+ method: StellarRequestMethods.stellar_disconnect,
161
+ params: void 0,
162
+ });
163
+ this._handleDisconnected();
164
+ });
165
+ }
166
+ }
167
+ exports.ProviderStellar = ProviderStellar;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProviderStellarBase = void 0;
4
+ const cross_inpage_provider_types_1 = require("@onekeyfe/cross-inpage-provider-types");
5
+ const cross_inpage_provider_core_1 = require("@onekeyfe/cross-inpage-provider-core");
6
+ class ProviderStellarBase extends cross_inpage_provider_core_1.ProviderBase {
7
+ constructor(props) {
8
+ super(props);
9
+ this.providerName = cross_inpage_provider_types_1.IInjectedProviderNames.stellar;
10
+ }
11
+ request(data) {
12
+ return this.bridgeRequest(data);
13
+ }
14
+ }
15
+ exports.ProviderStellarBase = ProviderStellarBase;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ProviderStellarHana = void 0;
13
+ /**
14
+ * Hana Wallet compatible wrapper for ProviderStellar
15
+ * Adapts OneKey Stellar Provider to match Hana wallet's interface
16
+ */
17
+ class ProviderStellarHana {
18
+ constructor(provider) {
19
+ this.provider = provider;
20
+ }
21
+ /**
22
+ * Get the public key of the current account
23
+ * @returns Promise<string> - The public key/address
24
+ */
25
+ getPublicKey() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const result = yield this.provider.getAddress();
28
+ return result.address;
29
+ });
30
+ }
31
+ /**
32
+ * Sign a transaction in XDR format
33
+ * @param params - Transaction signing parameters
34
+ * @returns Promise<string> - The signed transaction XDR
35
+ */
36
+ signTransaction(_a) {
37
+ return __awaiter(this, arguments, void 0, function* ({ xdr, accountToSign, networkPassphrase }) {
38
+ const result = yield this.provider.signTransaction(xdr, {
39
+ address: accountToSign,
40
+ networkPassphrase,
41
+ });
42
+ return result.signedTxXdr;
43
+ });
44
+ }
45
+ /**
46
+ * Sign a blob (arbitrary data)
47
+ * Note: This is implemented using signMessage as ProviderStellar doesn't have a separate blob signing method
48
+ * @param params - Blob signing parameters
49
+ * @returns Promise<string> - The signed blob
50
+ */
51
+ signBlob(_a) {
52
+ return __awaiter(this, arguments, void 0, function* ({ blob, accountToSign }) {
53
+ const result = yield this.provider.signMessage(blob, {
54
+ address: accountToSign,
55
+ });
56
+ return result.signedMessage;
57
+ });
58
+ }
59
+ /**
60
+ * Sign an AuthEntry in XDR format
61
+ * @param params - AuthEntry signing parameters
62
+ * @returns Promise<string> - The signed AuthEntry XDR
63
+ */
64
+ signAuthEntry(_a) {
65
+ return __awaiter(this, arguments, void 0, function* ({ xdr, accountToSign }) {
66
+ const result = yield this.provider.signAuthEntry(xdr, {
67
+ address: accountToSign,
68
+ });
69
+ return result.signedAuthEntry;
70
+ });
71
+ }
72
+ /**
73
+ * Sign an arbitrary message
74
+ * @param params - Message signing parameters
75
+ * @returns Promise<string> - The signed message
76
+ */
77
+ signMessage(_a) {
78
+ return __awaiter(this, arguments, void 0, function* ({ message, accountToSign }) {
79
+ const result = yield this.provider.signMessage(message, {
80
+ address: accountToSign,
81
+ });
82
+ return result.signedMessage;
83
+ });
84
+ }
85
+ /**
86
+ * Get the current network configuration
87
+ * @returns Promise<{network: string, networkPassphrase: string}>
88
+ */
89
+ getNetwork() {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ return this.provider.getNetwork();
92
+ });
93
+ }
94
+ /**
95
+ * Disconnect from the wallet
96
+ */
97
+ disconnect() {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ return this.provider.disconnect();
100
+ });
101
+ }
102
+ }
103
+ exports.ProviderStellarHana = ProviderStellarHana;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./OnekeyStellarProvider"), exports);
18
+ __exportStar(require("./ProviderStellarHana"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export * from './OnekeyStellarProvider';
2
+ export * from './ProviderStellarHana';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './OnekeyStellarProvider';
2
+ export * from './ProviderStellarHana';
@@ -0,0 +1,4 @@
1
+ export type WireStringified<T> = T extends Array<infer P> ? Array<WireStringified<P>> : T extends object ? {
2
+ [K in keyof T]: WireStringified<T[K]>;
3
+ } : T;
4
+ export type ResolvePromise<T> = T extends Promise<infer P> ? P : T;
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@onekeyfe/onekey-stellar-provider",
3
+ "version": "2.2.56-alpha.1",
4
+ "keywords": [
5
+ "cross-inpage-provider"
6
+ ],
7
+ "author": "dev-fe@onekey.so",
8
+ "repository": "https://github.com/OneKeyHQ/cross-inpage-provider",
9
+ "license": "Apache-2.0",
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "files": [
14
+ "dist/*"
15
+ ],
16
+ "exports": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js",
19
+ "require": "./dist/cjs/index.js"
20
+ },
21
+ "types": "./dist/index.d.ts",
22
+ "module": "./dist/index.js",
23
+ "main": "./dist/cjs/index.js",
24
+ "scripts": {
25
+ "prebuild": "rm -rf dist",
26
+ "build": "tsc && tsc --project tsconfig.cjs.json",
27
+ "start": "tsc --watch"
28
+ },
29
+ "dependencies": {
30
+ "@onekeyfe/cross-inpage-provider-core": "2.2.56-alpha.1",
31
+ "@onekeyfe/cross-inpage-provider-errors": "2.2.56-alpha.1",
32
+ "@onekeyfe/cross-inpage-provider-types": "2.2.56-alpha.1",
33
+ "@onekeyfe/extension-bridge-injected": "2.2.56-alpha.1"
34
+ },
35
+ "gitHead": "a1dfd47ff2a01a6aadbf7276f902b5f612c718c1"
36
+ }