@beaconmcu/auth 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,142 @@
1
+ type NetworkId = "testnet" | "mainnet";
2
+ type NetworkInfo = {
3
+ id: NetworkId;
4
+ name: string;
5
+ passphrase: string;
6
+ horizonUrl: string;
7
+ explorerUrl: string;
8
+ friendbotUrl?: string;
9
+ };
10
+ declare const NETWORKS: Record<NetworkId, NetworkInfo>;
11
+
12
+ type WalletError = {
13
+ error: {
14
+ code: number;
15
+ message: string;
16
+ };
17
+ };
18
+ interface StellarWalletInterface {
19
+ getAddress(): Promise<{
20
+ address: string;
21
+ } | WalletError>;
22
+ getNetwork(): Promise<{
23
+ network: string;
24
+ networkPassphrase: string;
25
+ } | WalletError>;
26
+ signTransaction(xdr: string, opts?: {
27
+ networkPassphrase?: string;
28
+ address?: string;
29
+ }): Promise<{
30
+ signedTxXdr: string;
31
+ signerAddress: string;
32
+ } | WalletError>;
33
+ signMessage(message: string, opts?: {
34
+ address?: string;
35
+ }): Promise<{
36
+ signedMessage: string;
37
+ signerAddress: string;
38
+ } | WalletError>;
39
+ signAuthEntry(authEntry: string, opts?: {
40
+ networkPassphrase?: string;
41
+ address?: string;
42
+ }): Promise<{
43
+ signedAuthEntry: string;
44
+ signerAddress: string;
45
+ } | WalletError>;
46
+ }
47
+
48
+ type BeaconOptions = {
49
+ /** Public Client ID from the Beacon dashboard (bcn_app_...). */
50
+ clientId: string;
51
+ /** Network used on login. Defaults to the app's network from the dashboard (testnet if none). */
52
+ defaultNetwork?: NetworkId;
53
+ /** Networks the app can switch between with switchNetwork(). Defaults to just the default network. */
54
+ supportedNetworks?: NetworkId[];
55
+ /** Defaults to https://wallet.beaconmcu.space */
56
+ walletUrl?: string;
57
+ /**
58
+ * Show the wallet's confirmation screen before signing. Default true.
59
+ * Set false to sign low-risk requests silently (messages and plain XLM payments from the user's own
60
+ * account). Anything risky (contract calls, account changes, other accounts) is always confirmed.
61
+ */
62
+ showWalletUI?: boolean;
63
+ };
64
+ type BeaconEventMap = {
65
+ connect: (info: {
66
+ address: string;
67
+ network: NetworkId;
68
+ }) => void;
69
+ disconnect: () => void;
70
+ accountChanged: (address: string | null) => void;
71
+ networkChanged: (network: NetworkId) => void;
72
+ };
73
+ declare class BeaconAuth {
74
+ private address;
75
+ private network;
76
+ private events;
77
+ private connection;
78
+ constructor(options: BeaconOptions);
79
+ /** Opens the wallet and signs the user in with Google. Resolves with the Stellar address (G...). */
80
+ login(): Promise<{
81
+ address: string;
82
+ }>;
83
+ logout(): Promise<void>;
84
+ /** Switches to another of the app's supportedNetworks. Rejects with code -6 for any other network. */
85
+ switchNetwork(network: NetworkId): Promise<void>;
86
+ /**
87
+ * Sends XLM in one call. The wallet builds the payment, asks the user to approve it, signs it and
88
+ * submits it. Resolves with the transaction hash. (To create a new account, send at least 1 XLM.)
89
+ */
90
+ sendPayment(payment: {
91
+ to: string;
92
+ amount: string;
93
+ memo?: string;
94
+ }): Promise<{
95
+ hash: string;
96
+ }>;
97
+ /** Signs a transaction (base64 XDR). Returns the signed XDR; submit it yourself, e.g. through Horizon. */
98
+ signTransaction(xdr: string, options?: {
99
+ networkPassphrase?: string;
100
+ address?: string;
101
+ }): Promise<{
102
+ signedTxXdr: string;
103
+ signerAddress: string;
104
+ }>;
105
+ /** Signs a text message (SEP-53). The signature is base64. */
106
+ signMessage(message: string, options?: {
107
+ address?: string;
108
+ }): Promise<{
109
+ signedMessage: string;
110
+ signerAddress: string;
111
+ }>;
112
+ /** Signs a Soroban authorization entry preimage (base64 XDR). Returns a base64 signature. */
113
+ signAuthEntry(preimage: string, options?: {
114
+ networkPassphrase?: string;
115
+ address?: string;
116
+ }): Promise<{
117
+ signedAuthEntry: string;
118
+ signerAddress: string;
119
+ }>;
120
+ getAddress(): string | null;
121
+ /** The active network (the default one until the wallet reports otherwise). */
122
+ getNetwork(): NetworkInfo;
123
+ /**
124
+ * The same functions in the standard Stellar wallet shape (SEP-43), for libraries such as
125
+ * Stellar Wallets Kit: getAddress, signTransaction, signMessage, signAuthEntry, getNetwork.
126
+ */
127
+ getWalletInterface(): StellarWalletInterface;
128
+ on<E extends keyof BeaconEventMap>(event: E, callback: BeaconEventMap[E]): () => void;
129
+ off<E extends keyof BeaconEventMap>(event: E, callback: BeaconEventMap[E]): void;
130
+ /** Removes the wallet iframe and listeners. */
131
+ destroy(): void;
132
+ private handleNetworkChanged;
133
+ private handleConnected;
134
+ private handleDisconnected;
135
+ }
136
+
137
+ declare class BeaconError extends Error {
138
+ code: number;
139
+ constructor(code: number, message: string);
140
+ }
141
+
142
+ export { BeaconAuth, BeaconError, type BeaconEventMap, type BeaconOptions, NETWORKS, type NetworkId, type NetworkInfo, type StellarWalletInterface };
@@ -0,0 +1,142 @@
1
+ type NetworkId = "testnet" | "mainnet";
2
+ type NetworkInfo = {
3
+ id: NetworkId;
4
+ name: string;
5
+ passphrase: string;
6
+ horizonUrl: string;
7
+ explorerUrl: string;
8
+ friendbotUrl?: string;
9
+ };
10
+ declare const NETWORKS: Record<NetworkId, NetworkInfo>;
11
+
12
+ type WalletError = {
13
+ error: {
14
+ code: number;
15
+ message: string;
16
+ };
17
+ };
18
+ interface StellarWalletInterface {
19
+ getAddress(): Promise<{
20
+ address: string;
21
+ } | WalletError>;
22
+ getNetwork(): Promise<{
23
+ network: string;
24
+ networkPassphrase: string;
25
+ } | WalletError>;
26
+ signTransaction(xdr: string, opts?: {
27
+ networkPassphrase?: string;
28
+ address?: string;
29
+ }): Promise<{
30
+ signedTxXdr: string;
31
+ signerAddress: string;
32
+ } | WalletError>;
33
+ signMessage(message: string, opts?: {
34
+ address?: string;
35
+ }): Promise<{
36
+ signedMessage: string;
37
+ signerAddress: string;
38
+ } | WalletError>;
39
+ signAuthEntry(authEntry: string, opts?: {
40
+ networkPassphrase?: string;
41
+ address?: string;
42
+ }): Promise<{
43
+ signedAuthEntry: string;
44
+ signerAddress: string;
45
+ } | WalletError>;
46
+ }
47
+
48
+ type BeaconOptions = {
49
+ /** Public Client ID from the Beacon dashboard (bcn_app_...). */
50
+ clientId: string;
51
+ /** Network used on login. Defaults to the app's network from the dashboard (testnet if none). */
52
+ defaultNetwork?: NetworkId;
53
+ /** Networks the app can switch between with switchNetwork(). Defaults to just the default network. */
54
+ supportedNetworks?: NetworkId[];
55
+ /** Defaults to https://wallet.beaconmcu.space */
56
+ walletUrl?: string;
57
+ /**
58
+ * Show the wallet's confirmation screen before signing. Default true.
59
+ * Set false to sign low-risk requests silently (messages and plain XLM payments from the user's own
60
+ * account). Anything risky (contract calls, account changes, other accounts) is always confirmed.
61
+ */
62
+ showWalletUI?: boolean;
63
+ };
64
+ type BeaconEventMap = {
65
+ connect: (info: {
66
+ address: string;
67
+ network: NetworkId;
68
+ }) => void;
69
+ disconnect: () => void;
70
+ accountChanged: (address: string | null) => void;
71
+ networkChanged: (network: NetworkId) => void;
72
+ };
73
+ declare class BeaconAuth {
74
+ private address;
75
+ private network;
76
+ private events;
77
+ private connection;
78
+ constructor(options: BeaconOptions);
79
+ /** Opens the wallet and signs the user in with Google. Resolves with the Stellar address (G...). */
80
+ login(): Promise<{
81
+ address: string;
82
+ }>;
83
+ logout(): Promise<void>;
84
+ /** Switches to another of the app's supportedNetworks. Rejects with code -6 for any other network. */
85
+ switchNetwork(network: NetworkId): Promise<void>;
86
+ /**
87
+ * Sends XLM in one call. The wallet builds the payment, asks the user to approve it, signs it and
88
+ * submits it. Resolves with the transaction hash. (To create a new account, send at least 1 XLM.)
89
+ */
90
+ sendPayment(payment: {
91
+ to: string;
92
+ amount: string;
93
+ memo?: string;
94
+ }): Promise<{
95
+ hash: string;
96
+ }>;
97
+ /** Signs a transaction (base64 XDR). Returns the signed XDR; submit it yourself, e.g. through Horizon. */
98
+ signTransaction(xdr: string, options?: {
99
+ networkPassphrase?: string;
100
+ address?: string;
101
+ }): Promise<{
102
+ signedTxXdr: string;
103
+ signerAddress: string;
104
+ }>;
105
+ /** Signs a text message (SEP-53). The signature is base64. */
106
+ signMessage(message: string, options?: {
107
+ address?: string;
108
+ }): Promise<{
109
+ signedMessage: string;
110
+ signerAddress: string;
111
+ }>;
112
+ /** Signs a Soroban authorization entry preimage (base64 XDR). Returns a base64 signature. */
113
+ signAuthEntry(preimage: string, options?: {
114
+ networkPassphrase?: string;
115
+ address?: string;
116
+ }): Promise<{
117
+ signedAuthEntry: string;
118
+ signerAddress: string;
119
+ }>;
120
+ getAddress(): string | null;
121
+ /** The active network (the default one until the wallet reports otherwise). */
122
+ getNetwork(): NetworkInfo;
123
+ /**
124
+ * The same functions in the standard Stellar wallet shape (SEP-43), for libraries such as
125
+ * Stellar Wallets Kit: getAddress, signTransaction, signMessage, signAuthEntry, getNetwork.
126
+ */
127
+ getWalletInterface(): StellarWalletInterface;
128
+ on<E extends keyof BeaconEventMap>(event: E, callback: BeaconEventMap[E]): () => void;
129
+ off<E extends keyof BeaconEventMap>(event: E, callback: BeaconEventMap[E]): void;
130
+ /** Removes the wallet iframe and listeners. */
131
+ destroy(): void;
132
+ private handleNetworkChanged;
133
+ private handleConnected;
134
+ private handleDisconnected;
135
+ }
136
+
137
+ declare class BeaconError extends Error {
138
+ code: number;
139
+ constructor(code: number, message: string);
140
+ }
141
+
142
+ export { BeaconAuth, BeaconError, type BeaconEventMap, type BeaconOptions, NETWORKS, type NetworkId, type NetworkInfo, type StellarWalletInterface };