@cosmosapp/pay_sdk 2.3.2 → 2.4.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.
- package/CHANGELOG.md +19 -0
- package/README.md +97 -61
- package/dist/{chunk-U3WDM2FJ.js → chunk-6FIALX2E.js} +3 -3
- package/dist/{chunk-U3WDM2FJ.js.map → chunk-6FIALX2E.js.map} +1 -1
- package/dist/chunk-ALFITFBN.js +105 -0
- package/dist/chunk-ALFITFBN.js.map +1 -0
- package/dist/chunk-PAQHOXQ6.js +392 -0
- package/dist/chunk-PAQHOXQ6.js.map +1 -0
- package/dist/errors-CZu5mmz1.d.cts +293 -0
- package/dist/errors-Cqh7UdUO.d.ts +293 -0
- package/dist/index.cjs +18 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -7
- package/dist/index.d.ts +12 -7
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/dist/intent-input-BybnwL83.d.ts +126 -0
- package/dist/intent-input-C2PTr2XH.d.cts +126 -0
- package/dist/swk/index.js +1 -103
- package/dist/swk/index.js.map +1 -1
- package/dist/wallets/index.cjs +1043 -0
- package/dist/wallets/index.cjs.map +1 -0
- package/dist/wallets/index.d.cts +384 -0
- package/dist/wallets/index.d.ts +384 -0
- package/dist/wallets/index.js +629 -0
- package/dist/wallets/index.js.map +1 -0
- package/dist/{intent-input-CP5bkBYI.d.cts → wallets-CeIjESt5.d.cts} +39 -126
- package/dist/{intent-input-CP5bkBYI.d.ts → wallets-CeIjESt5.d.ts} +39 -126
- package/dist/web/index.cjs +1 -1
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.d.cts +7 -292
- package/dist/web/index.d.ts +7 -292
- package/dist/web/index.js +5 -391
- package/dist/web/index.js.map +1 -1
- package/llms/07-webhooks.md +2 -0
- package/llms/15-swaps.md +2 -0
- package/llms/18-wallets.md +94 -0
- package/llms/llms-full.txt +101 -0
- package/llms/llms.txt +1 -0
- package/package.json +22 -8
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { c1 as AssetRef } from './wallets-CeIjESt5.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Error thrown when the Cosmos Pay API responds with a non-2xx status.
|
|
5
|
+
*
|
|
6
|
+
* Carries the HTTP status, the parsed response body and the request context so
|
|
7
|
+
* callers can branch on `error.status` (e.g. 404 → not found, 403 → gateway).
|
|
8
|
+
*/
|
|
9
|
+
declare class CosmosPayAPIError extends Error {
|
|
10
|
+
/** HTTP status code returned by the API. */
|
|
11
|
+
readonly status: number;
|
|
12
|
+
/** HTTP method of the failed request. */
|
|
13
|
+
readonly method: string;
|
|
14
|
+
/** Absolute URL of the failed request. */
|
|
15
|
+
readonly url: string;
|
|
16
|
+
/** Parsed response body (object when JSON, string otherwise, or null). */
|
|
17
|
+
readonly body: unknown;
|
|
18
|
+
/** Machine-readable error code extracted from the body when present. */
|
|
19
|
+
readonly code: string | undefined;
|
|
20
|
+
constructor(options: {
|
|
21
|
+
status: number;
|
|
22
|
+
method: string;
|
|
23
|
+
url: string;
|
|
24
|
+
body: unknown;
|
|
25
|
+
});
|
|
26
|
+
private static resolveMessage;
|
|
27
|
+
private static resolveCode;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Error thrown when a request never reaches the API: network failure, abort or
|
|
31
|
+
* timeout. Distinct from {@link CosmosPayAPIError}, which always has a status.
|
|
32
|
+
*/
|
|
33
|
+
declare class CosmosPayRequestError extends Error {
|
|
34
|
+
readonly method: string;
|
|
35
|
+
readonly url: string;
|
|
36
|
+
readonly cause: unknown;
|
|
37
|
+
constructor(options: {
|
|
38
|
+
method: string;
|
|
39
|
+
url: string;
|
|
40
|
+
cause: unknown;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Stellar address helpers + a tiny named-address book.
|
|
46
|
+
*
|
|
47
|
+
* So integrators don't have to sprinkle raw `G...` strings everywhere (and risk
|
|
48
|
+
* typos), they can name the accounts they care about once and reference them by
|
|
49
|
+
* name. A plain address string always keeps working — `resolveAddress` only
|
|
50
|
+
* substitutes registered names and otherwise passes the value straight through.
|
|
51
|
+
*/
|
|
52
|
+
/** Whether a value looks like a Stellar account address (`G…`). */
|
|
53
|
+
declare function isStellarAddress(value: unknown): value is string;
|
|
54
|
+
/** Whether a value looks like a muxed account address (`M…`). */
|
|
55
|
+
declare function isMuxedAddress(value: unknown): value is string;
|
|
56
|
+
/** Whether a value looks like a Soroban contract id (`C…`). */
|
|
57
|
+
declare function isContractAddress(value: unknown): value is string;
|
|
58
|
+
/** Whether a value is any kind of Stellar address (account, muxed or contract). */
|
|
59
|
+
declare function isAddress(value: unknown): value is string;
|
|
60
|
+
/** Throw unless `value` is a valid Stellar account/muxed/contract address. */
|
|
61
|
+
declare function assertAddress(value: unknown, label?: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* A registry of named Stellar addresses. Register the accounts you use a lot —
|
|
64
|
+
* your merchant payout account, a treasury, frequent counterparties — and refer
|
|
65
|
+
* to them by name anywhere an address is accepted.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* addresses.define('merchant', 'GC...');
|
|
69
|
+
* await client.paymentIntents.createPay({ destination: 'merchant', amount: '10' });
|
|
70
|
+
*/
|
|
71
|
+
declare class AddressBook {
|
|
72
|
+
private readonly entries;
|
|
73
|
+
constructor(initial?: Record<string, string>);
|
|
74
|
+
/** Register (or overwrite) a named address. The address is validated. */
|
|
75
|
+
define(name: string, address: string): this;
|
|
76
|
+
/** Whether a name is registered. */
|
|
77
|
+
has(name: string): boolean;
|
|
78
|
+
/** Look up a registered address by name. */
|
|
79
|
+
get(name: string): string | undefined;
|
|
80
|
+
/** Remove a named address. */
|
|
81
|
+
delete(name: string): boolean;
|
|
82
|
+
/** All registered names. */
|
|
83
|
+
names(): string[];
|
|
84
|
+
/**
|
|
85
|
+
* Resolve a reference to a concrete address: a registered name is substituted,
|
|
86
|
+
* any other string is returned unchanged (so raw `G…`, muxed `M…`, federation
|
|
87
|
+
* `name*domain`, etc. all keep working).
|
|
88
|
+
*/
|
|
89
|
+
resolve(ref: string): string;
|
|
90
|
+
}
|
|
91
|
+
/** Process-wide default address book. Use `addresses.define(...)` to populate it. */
|
|
92
|
+
declare const addresses: AddressBook;
|
|
93
|
+
/** Anything accepted where an address is expected: a raw address or a name in a book. */
|
|
94
|
+
type AddressRef = string;
|
|
95
|
+
/**
|
|
96
|
+
* Resolve an {@link AddressRef} using the given book (the shared {@link addresses}
|
|
97
|
+
* by default). Lenient: unknown strings pass through unchanged.
|
|
98
|
+
*/
|
|
99
|
+
declare function resolveAddress(ref: AddressRef, book?: AddressBook): string;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Shared resolution of "create intent" input, used by both the server SDK and
|
|
103
|
+
* the web client so the convenience layers behave identically: a typed
|
|
104
|
+
* {@link AssetRef} (e.g. `Assets.USDC`) is expanded into `assetCode`/`assetIssuer`,
|
|
105
|
+
* and named addresses are substituted via an {@link AddressBook}.
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
/** Fields the resolver understands (everything else passes through untouched). */
|
|
109
|
+
interface ResolvableIntentInput {
|
|
110
|
+
destination?: string;
|
|
111
|
+
source?: string;
|
|
112
|
+
/** Typed asset (`Assets.USDC`, `defineAsset(...)`) — fills code + issuer. */
|
|
113
|
+
asset?: AssetRef;
|
|
114
|
+
assetCode?: string;
|
|
115
|
+
assetIssuer?: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Expand `asset` into `assetCode`/`assetIssuer` and resolve named
|
|
119
|
+
* `destination`/`source` addresses. Existing `assetCode`/`assetIssuer` win over a
|
|
120
|
+
* provided `asset`; native assets leave the code unset (the API treats an omitted
|
|
121
|
+
* asset as native XLM). Returns a new object — the input is not mutated.
|
|
122
|
+
*/
|
|
123
|
+
declare function resolveIntentBody<T extends ResolvableIntentInput>(options: T, book?: AddressBook): Omit<T, 'asset'>;
|
|
124
|
+
|
|
125
|
+
export { AddressBook as A, CosmosPayAPIError as C, CosmosPayRequestError as b, addresses as c, assertAddress as d, isContractAddress as e, isMuxedAddress as f, isStellarAddress as g, resolveIntentBody as h, isAddress as i, resolveAddress as r };
|
|
126
|
+
export type { ResolvableIntentInput as R, AddressRef as a };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { c1 as AssetRef } from './wallets-CeIjESt5.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Error thrown when the Cosmos Pay API responds with a non-2xx status.
|
|
5
|
+
*
|
|
6
|
+
* Carries the HTTP status, the parsed response body and the request context so
|
|
7
|
+
* callers can branch on `error.status` (e.g. 404 → not found, 403 → gateway).
|
|
8
|
+
*/
|
|
9
|
+
declare class CosmosPayAPIError extends Error {
|
|
10
|
+
/** HTTP status code returned by the API. */
|
|
11
|
+
readonly status: number;
|
|
12
|
+
/** HTTP method of the failed request. */
|
|
13
|
+
readonly method: string;
|
|
14
|
+
/** Absolute URL of the failed request. */
|
|
15
|
+
readonly url: string;
|
|
16
|
+
/** Parsed response body (object when JSON, string otherwise, or null). */
|
|
17
|
+
readonly body: unknown;
|
|
18
|
+
/** Machine-readable error code extracted from the body when present. */
|
|
19
|
+
readonly code: string | undefined;
|
|
20
|
+
constructor(options: {
|
|
21
|
+
status: number;
|
|
22
|
+
method: string;
|
|
23
|
+
url: string;
|
|
24
|
+
body: unknown;
|
|
25
|
+
});
|
|
26
|
+
private static resolveMessage;
|
|
27
|
+
private static resolveCode;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Error thrown when a request never reaches the API: network failure, abort or
|
|
31
|
+
* timeout. Distinct from {@link CosmosPayAPIError}, which always has a status.
|
|
32
|
+
*/
|
|
33
|
+
declare class CosmosPayRequestError extends Error {
|
|
34
|
+
readonly method: string;
|
|
35
|
+
readonly url: string;
|
|
36
|
+
readonly cause: unknown;
|
|
37
|
+
constructor(options: {
|
|
38
|
+
method: string;
|
|
39
|
+
url: string;
|
|
40
|
+
cause: unknown;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Stellar address helpers + a tiny named-address book.
|
|
46
|
+
*
|
|
47
|
+
* So integrators don't have to sprinkle raw `G...` strings everywhere (and risk
|
|
48
|
+
* typos), they can name the accounts they care about once and reference them by
|
|
49
|
+
* name. A plain address string always keeps working — `resolveAddress` only
|
|
50
|
+
* substitutes registered names and otherwise passes the value straight through.
|
|
51
|
+
*/
|
|
52
|
+
/** Whether a value looks like a Stellar account address (`G…`). */
|
|
53
|
+
declare function isStellarAddress(value: unknown): value is string;
|
|
54
|
+
/** Whether a value looks like a muxed account address (`M…`). */
|
|
55
|
+
declare function isMuxedAddress(value: unknown): value is string;
|
|
56
|
+
/** Whether a value looks like a Soroban contract id (`C…`). */
|
|
57
|
+
declare function isContractAddress(value: unknown): value is string;
|
|
58
|
+
/** Whether a value is any kind of Stellar address (account, muxed or contract). */
|
|
59
|
+
declare function isAddress(value: unknown): value is string;
|
|
60
|
+
/** Throw unless `value` is a valid Stellar account/muxed/contract address. */
|
|
61
|
+
declare function assertAddress(value: unknown, label?: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* A registry of named Stellar addresses. Register the accounts you use a lot —
|
|
64
|
+
* your merchant payout account, a treasury, frequent counterparties — and refer
|
|
65
|
+
* to them by name anywhere an address is accepted.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* addresses.define('merchant', 'GC...');
|
|
69
|
+
* await client.paymentIntents.createPay({ destination: 'merchant', amount: '10' });
|
|
70
|
+
*/
|
|
71
|
+
declare class AddressBook {
|
|
72
|
+
private readonly entries;
|
|
73
|
+
constructor(initial?: Record<string, string>);
|
|
74
|
+
/** Register (or overwrite) a named address. The address is validated. */
|
|
75
|
+
define(name: string, address: string): this;
|
|
76
|
+
/** Whether a name is registered. */
|
|
77
|
+
has(name: string): boolean;
|
|
78
|
+
/** Look up a registered address by name. */
|
|
79
|
+
get(name: string): string | undefined;
|
|
80
|
+
/** Remove a named address. */
|
|
81
|
+
delete(name: string): boolean;
|
|
82
|
+
/** All registered names. */
|
|
83
|
+
names(): string[];
|
|
84
|
+
/**
|
|
85
|
+
* Resolve a reference to a concrete address: a registered name is substituted,
|
|
86
|
+
* any other string is returned unchanged (so raw `G…`, muxed `M…`, federation
|
|
87
|
+
* `name*domain`, etc. all keep working).
|
|
88
|
+
*/
|
|
89
|
+
resolve(ref: string): string;
|
|
90
|
+
}
|
|
91
|
+
/** Process-wide default address book. Use `addresses.define(...)` to populate it. */
|
|
92
|
+
declare const addresses: AddressBook;
|
|
93
|
+
/** Anything accepted where an address is expected: a raw address or a name in a book. */
|
|
94
|
+
type AddressRef = string;
|
|
95
|
+
/**
|
|
96
|
+
* Resolve an {@link AddressRef} using the given book (the shared {@link addresses}
|
|
97
|
+
* by default). Lenient: unknown strings pass through unchanged.
|
|
98
|
+
*/
|
|
99
|
+
declare function resolveAddress(ref: AddressRef, book?: AddressBook): string;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Shared resolution of "create intent" input, used by both the server SDK and
|
|
103
|
+
* the web client so the convenience layers behave identically: a typed
|
|
104
|
+
* {@link AssetRef} (e.g. `Assets.USDC`) is expanded into `assetCode`/`assetIssuer`,
|
|
105
|
+
* and named addresses are substituted via an {@link AddressBook}.
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
/** Fields the resolver understands (everything else passes through untouched). */
|
|
109
|
+
interface ResolvableIntentInput {
|
|
110
|
+
destination?: string;
|
|
111
|
+
source?: string;
|
|
112
|
+
/** Typed asset (`Assets.USDC`, `defineAsset(...)`) — fills code + issuer. */
|
|
113
|
+
asset?: AssetRef;
|
|
114
|
+
assetCode?: string;
|
|
115
|
+
assetIssuer?: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Expand `asset` into `assetCode`/`assetIssuer` and resolve named
|
|
119
|
+
* `destination`/`source` addresses. Existing `assetCode`/`assetIssuer` win over a
|
|
120
|
+
* provided `asset`; native assets leave the code unset (the API treats an omitted
|
|
121
|
+
* asset as native XLM). Returns a new object — the input is not mutated.
|
|
122
|
+
*/
|
|
123
|
+
declare function resolveIntentBody<T extends ResolvableIntentInput>(options: T, book?: AddressBook): Omit<T, 'asset'>;
|
|
124
|
+
|
|
125
|
+
export { AddressBook as A, CosmosPayAPIError as C, CosmosPayRequestError as b, addresses as c, assertAddress as d, isContractAddress as e, isMuxedAddress as f, isStellarAddress as g, resolveIntentBody as h, isAddress as i, resolveAddress as r };
|
|
126
|
+
export type { ResolvableIntentInput as R, AddressRef as a };
|
package/dist/swk/index.js
CHANGED
|
@@ -1,106 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export { COSMOS_WALLET_ID, CosmosWalletModule, SwkModuleType } from '../chunk-ALFITFBN.js';
|
|
2
2
|
export { injectedProvider, loadHostedProvider, resetProviderCache, resolveProvider } from '../chunk-6PHQBYQ4.js';
|
|
3
|
-
|
|
4
|
-
// src/swk/types.ts
|
|
5
|
-
var SwkModuleType = {
|
|
6
|
-
HW_WALLET: "HW_WALLET",
|
|
7
|
-
HOT_WALLET: "HOT_WALLET",
|
|
8
|
-
BRIDGE_WALLET: "BRIDGE_WALLET",
|
|
9
|
-
AIR_GAPED_WALLET: "AIR_GAPED_WALLET"
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// src/swk/CosmosWalletModule.ts
|
|
13
|
-
var COSMOS_WALLET_ID = "cosmos-wallet";
|
|
14
|
-
var PRODUCT_NAME = "Cosmos Pay Wallet";
|
|
15
|
-
var PRODUCT_URL = "https://github.com/CosmosPay/CosmosPay-Wallet";
|
|
16
|
-
var PRODUCT_ICON = "https://raw.githubusercontent.com/CosmosPay/CosmosPay-Wallet/main/public/logo-512.png";
|
|
17
|
-
var NOT_SUPPORTED = -3;
|
|
18
|
-
var CosmosWalletModule = class {
|
|
19
|
-
constructor(options = {}) {
|
|
20
|
-
this.productId = COSMOS_WALLET_ID;
|
|
21
|
-
this.moduleType = options.moduleType ?? SwkModuleType.HOT_WALLET;
|
|
22
|
-
this.productName = options.productName ?? PRODUCT_NAME;
|
|
23
|
-
this.productUrl = options.productUrl ?? PRODUCT_URL;
|
|
24
|
-
this.productIcon = options.productIcon ?? PRODUCT_ICON;
|
|
25
|
-
this.options = {
|
|
26
|
-
provider: options.provider,
|
|
27
|
-
walletUrl: options.walletUrl,
|
|
28
|
-
loadTimeoutMs: options.loadTimeoutMs
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* The kit allows 1000ms for this and shows the wallet as unavailable otherwise,
|
|
33
|
-
* so it answers from what is already in the page: an injected provider, or a
|
|
34
|
-
* configured hosted wallet — which needs no install and is therefore always
|
|
35
|
-
* usable. The hosted script itself is fetched on the first real call.
|
|
36
|
-
*/
|
|
37
|
-
async isAvailable() {
|
|
38
|
-
if (this.options.provider) return true;
|
|
39
|
-
if (injectedProvider()) return true;
|
|
40
|
-
return !!this.options.walletUrl;
|
|
41
|
-
}
|
|
42
|
-
async provider() {
|
|
43
|
-
const provider = await resolveProvider(this.options);
|
|
44
|
-
if (!provider) throw kitError(`${this.productName} is not available.`, -1);
|
|
45
|
-
return provider;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* `skipRequestAccess` is accepted and ignored on purpose: the wallet decides
|
|
49
|
-
* whether an origin it already knows needs to be asked again, and a dapp asking
|
|
50
|
-
* to skip the prompt is not the party that gets to decide that.
|
|
51
|
-
*/
|
|
52
|
-
async getAddress(_params) {
|
|
53
|
-
const provider = await this.provider();
|
|
54
|
-
const { address } = await provider.getAddress();
|
|
55
|
-
if (!address) throw kitError("The wallet returned no address.", -1);
|
|
56
|
-
return { address };
|
|
57
|
-
}
|
|
58
|
-
async signTransaction(xdr, opts) {
|
|
59
|
-
const provider = await this.provider();
|
|
60
|
-
const result = await provider.signTransaction(xdr, {
|
|
61
|
-
networkPassphrase: opts?.networkPassphrase,
|
|
62
|
-
address: opts?.address
|
|
63
|
-
});
|
|
64
|
-
if (!result?.signedTxXdr) throw kitError("The wallet returned no signed transaction.", -1);
|
|
65
|
-
return { signedTxXdr: result.signedTxXdr, signerAddress: result.signerAddress };
|
|
66
|
-
}
|
|
67
|
-
async signMessage(message, opts) {
|
|
68
|
-
const provider = await this.provider();
|
|
69
|
-
const result = await provider.signMessage(message, {
|
|
70
|
-
networkPassphrase: opts?.networkPassphrase,
|
|
71
|
-
address: opts?.address
|
|
72
|
-
});
|
|
73
|
-
if (!result?.signedMessage) throw kitError("The wallet returned no signature.", -1);
|
|
74
|
-
return { signedMessage: result.signedMessage, signerAddress: result.signerAddress };
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Not supported, and reported as such in the kit's own vocabulary.
|
|
78
|
-
*
|
|
79
|
-
* Cosmos Pay Wallet has no Soroban authorization-entry signing. Anything this could
|
|
80
|
-
* return instead of an error would be a signature the network rejects, discovered
|
|
81
|
-
* by the user rather than by the dapp.
|
|
82
|
-
*/
|
|
83
|
-
signAuthEntry() {
|
|
84
|
-
return Promise.reject(
|
|
85
|
-
kitError(`${this.productName} does not support the "signAuthEntry" function`, NOT_SUPPORTED)
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* The network the WALLET is on, which is the only one it will sign for. A dapp
|
|
90
|
-
* that wants another network has to ask the user to switch, not ask the wallet to
|
|
91
|
-
* pretend.
|
|
92
|
-
*/
|
|
93
|
-
async getNetwork() {
|
|
94
|
-
const provider = await this.provider();
|
|
95
|
-
const { network, networkPassphrase } = await provider.getNetwork();
|
|
96
|
-
if (!networkPassphrase) throw kitError("The wallet returned no network.", -1);
|
|
97
|
-
return { network, networkPassphrase };
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
function kitError(message, code) {
|
|
101
|
-
return Object.assign(new Error(message), { code, message });
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export { COSMOS_WALLET_ID, CosmosWalletModule, SwkModuleType };
|
|
105
3
|
//# sourceMappingURL=index.js.map
|
|
106
4
|
//# sourceMappingURL=index.js.map
|
package/dist/swk/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/swk/types.ts","../../src/swk/CosmosWalletModule.ts"],"names":[],"mappings":"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","file":"index.js","sourcesContent":["/**\n * The Stellar Wallets Kit module contract, transcribed.\n *\n * WHY A COPY INSTEAD OF AN IMPORT. A module is one small class; depending on the\n * whole kit to describe it would put a UI library (and, when this was measured, 22\n * dev advisories) into an SDK whose own dependency list is empty. The kit is what a\n * CONSUMER installs — this package only has to produce something that fits it.\n *\n * The shapes below are transcribed from `@creit.tech/stellar-wallets-kit@2.6`\n * (`esm/types/mod.d.ts`) and are structural, so a module written against them is\n * assignable to the kit's `ModuleInterface` without either side knowing about the\n * other. The one place structural typing does not reach is `moduleType`: the kit\n * declares it as a string ENUM, and TypeScript does not accept a plain string\n * literal for one. `CosmosWalletModule` is therefore generic in that property —\n * pass the kit's own `ModuleType.HOT_WALLET` and it type-checks exactly; pass\n * nothing and you get the same string at runtime.\n *\n * Keep this file in step with the kit when it moves. `signAndSubmitTransaction` and\n * `isPlatformWrapper` are deliberately absent below: they are optional in the kit\n * and Cosmos Pay Wallet implements neither.\n */\n\n/** `moduleType` values the kit filters and groups by. */\nexport const SwkModuleType = {\n HW_WALLET: 'HW_WALLET',\n HOT_WALLET: 'HOT_WALLET',\n BRIDGE_WALLET: 'BRIDGE_WALLET',\n AIR_GAPED_WALLET: 'AIR_GAPED_WALLET',\n} as const;\n\nexport type SwkModuleTypeValue = (typeof SwkModuleType)[keyof typeof SwkModuleType];\n\n/**\n * What a module rejects with. The kit's `parseError` reads `code`, `message` and\n * `ext` off whatever it catches, so a plain object is the native shape — and `-3`\n * is the code its own modules use for \"this wallet cannot do that\".\n */\nexport interface IKitError {\n code: number;\n message: string;\n ext?: string;\n}\n\n/** Payload of the optional `onChange` subscription. */\nexport interface IOnChangeEvent {\n address: string;\n /** Human-readable network name, as the wallet calls it. */\n network: string;\n networkPassphrase: string;\n error?: IKitError;\n}\n\n/** Options every signing method accepts. `path` is for hardware wallets. */\nexport interface SwkSignOptions {\n networkPassphrase?: string;\n address?: string;\n path?: string;\n}\n\n/**\n * The kit's `ModuleInterface`, minus the optional members Cosmos Pay Wallet does not\n * implement. `TModuleType` exists only so the kit's enum can flow through — see\n * the header.\n */\nexport interface SwkModule<TModuleType extends string = SwkModuleTypeValue> {\n moduleType: TModuleType;\n productId: string;\n productName: string;\n productUrl: string;\n productIcon: string;\n /** Must answer in under 1000ms or the kit renders the wallet as unavailable. */\n isAvailable(): Promise<boolean>;\n getAddress(params?: { path?: string; skipRequestAccess?: boolean }): Promise<{ address: string }>;\n signTransaction(\n xdr: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedTxXdr: string; signerAddress?: string }>;\n signAuthEntry(\n authEntry: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedAuthEntry: string; signerAddress?: string }>;\n signMessage(\n message: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedMessage: string; signerAddress?: string }>;\n getNetwork(): Promise<{ network: string; networkPassphrase: string }>;\n onChange?(callback: (event: IOnChangeEvent) => void): void;\n disconnect?(): Promise<void>;\n}\n","/**\n * Cosmos Pay Wallet as a Stellar Wallets Kit module.\n *\n * The kit is how most Stellar dapps ask for a signature: they register a list of\n * modules and it renders one button per wallet. A wallet that is not a module is a\n * wallet those dapps cannot see, however good its provider is — which is the whole\n * reason this file exists. Registering it:\n *\n * ```ts\n * import { StellarWalletsKit, WalletNetwork, ModuleType } from '@creit.tech/stellar-wallets-kit';\n * import { CosmosWalletModule, COSMOS_WALLET_ID } from '@cosmosapp/pay_sdk/swk';\n *\n * const kit = new StellarWalletsKit({\n * network: WalletNetwork.PUBLIC,\n * selectedWalletId: COSMOS_WALLET_ID,\n * modules: [\n * // `moduleType` is the kit's own enum — passing it here keeps the module\n * // exactly assignable to `ModuleInterface` with no cast anywhere.\n * new CosmosWalletModule({ moduleType: ModuleType.HOT_WALLET }),\n * ],\n * });\n * ```\n *\n * TWO TRANSPORTS, ONE MODULE. With the extension installed the provider is already\n * on the page. Without it, pass `walletUrl` and the hosted wallet's provider script\n * is fetched from that origin on first use, so a dapp can offer Cosmos Pay Wallet to\n * users who have installed nothing:\n *\n * ```ts\n * new CosmosWalletModule({ walletUrl: 'https://wallet.cosmospay.lat' })\n * ```\n *\n * WHAT IT REFUSES, AND WHY THAT IS THE POINT. `signAuthEntry` rejects with the\n * kit's own `-3` \"not supported\" shape rather than returning something. Cosmos\n * Wallet signs transactions and domain-separated messages; it does not sign Soroban\n * authorization entries, and a module that faked one would hand a dapp a signature\n * that fails on chain instead of an error it can render.\n */\n\nimport {\n injectedProvider,\n resolveProvider,\n type CosmosProviderOptions,\n type CosmosWalletProvider,\n} from '@/web/cosmosProvider';\nimport { SwkModuleType, type IKitError, type SwkModule, type SwkSignOptions } from '@/swk/types';\n\n/** The id a dapp filters or preselects this wallet by. */\nexport const COSMOS_WALLET_ID = 'cosmos-wallet';\n\nconst PRODUCT_NAME = 'Cosmos Pay Wallet';\nconst PRODUCT_URL = 'https://github.com/CosmosPay/CosmosPay-Wallet';\n/**\n * Served from the wallet's repository so the module has nothing to host. When this\n * module is upstreamed the kit serves its own copy from `stellar.creit.tech`, which\n * is why the URL is an option rather than a constant baked into every call site.\n */\nconst PRODUCT_ICON =\n 'https://raw.githubusercontent.com/CosmosPay/CosmosPay-Wallet/main/public/logo-512.png';\n\n/** The kit's code for \"this wallet cannot do that\" (see its own modules). */\nconst NOT_SUPPORTED = -3;\n\nexport interface CosmosWalletModuleOptions<TModuleType extends string = string>\n extends CosmosProviderOptions {\n /**\n * Pass the kit's `ModuleType.HOT_WALLET` for exact typing. Defaults to the same\n * string, which is what the enum holds at runtime.\n */\n moduleType?: TModuleType;\n /** Override the name shown in the kit's modal. */\n productName?: string;\n /** Override the \"get this wallet\" link. */\n productUrl?: string;\n /** Override the icon shown in the modal. */\n productIcon?: string;\n}\n\nexport class CosmosWalletModule<TModuleType extends string = string>\n implements SwkModule<TModuleType>\n{\n public readonly moduleType: TModuleType;\n public readonly productId: string = COSMOS_WALLET_ID;\n public readonly productName: string;\n public readonly productUrl: string;\n public readonly productIcon: string;\n\n private readonly options: CosmosProviderOptions;\n\n constructor(options: CosmosWalletModuleOptions<TModuleType> = {}) {\n this.moduleType = (options.moduleType ?? SwkModuleType.HOT_WALLET) as TModuleType;\n this.productName = options.productName ?? PRODUCT_NAME;\n this.productUrl = options.productUrl ?? PRODUCT_URL;\n this.productIcon = options.productIcon ?? PRODUCT_ICON;\n this.options = {\n provider: options.provider,\n walletUrl: options.walletUrl,\n loadTimeoutMs: options.loadTimeoutMs,\n };\n }\n\n /**\n * The kit allows 1000ms for this and shows the wallet as unavailable otherwise,\n * so it answers from what is already in the page: an injected provider, or a\n * configured hosted wallet — which needs no install and is therefore always\n * usable. The hosted script itself is fetched on the first real call.\n */\n public async isAvailable(): Promise<boolean> {\n if (this.options.provider) return true;\n if (injectedProvider()) return true;\n return !!this.options.walletUrl;\n }\n\n private async provider(): Promise<CosmosWalletProvider> {\n const provider = await resolveProvider(this.options);\n if (!provider) throw kitError(`${this.productName} is not available.`, -1);\n return provider;\n }\n\n /**\n * `skipRequestAccess` is accepted and ignored on purpose: the wallet decides\n * whether an origin it already knows needs to be asked again, and a dapp asking\n * to skip the prompt is not the party that gets to decide that.\n */\n public async getAddress(_params?: { path?: string; skipRequestAccess?: boolean }): Promise<{\n address: string;\n }> {\n const provider = await this.provider();\n const { address } = await provider.getAddress();\n if (!address) throw kitError('The wallet returned no address.', -1);\n return { address };\n }\n\n public async signTransaction(\n xdr: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedTxXdr: string; signerAddress?: string }> {\n const provider = await this.provider();\n // The passphrase is forwarded, not authoritative: Cosmos Pay Wallet parses with its\n // own network configuration and REFUSES a mismatch, so a caller cannot redirect\n // a signature to another network by naming one. Forwarding it is what turns a\n // wrong-network request into an error the dapp can show.\n const result = await provider.signTransaction(xdr, {\n networkPassphrase: opts?.networkPassphrase,\n address: opts?.address,\n });\n if (!result?.signedTxXdr) throw kitError('The wallet returned no signed transaction.', -1);\n return { signedTxXdr: result.signedTxXdr, signerAddress: result.signerAddress };\n }\n\n public async signMessage(\n message: string,\n opts?: SwkSignOptions,\n ): Promise<{ signedMessage: string; signerAddress?: string }> {\n const provider = await this.provider();\n const result = await provider.signMessage(message, {\n networkPassphrase: opts?.networkPassphrase,\n address: opts?.address,\n });\n if (!result?.signedMessage) throw kitError('The wallet returned no signature.', -1);\n return { signedMessage: result.signedMessage, signerAddress: result.signerAddress };\n }\n\n /**\n * Not supported, and reported as such in the kit's own vocabulary.\n *\n * Cosmos Pay Wallet has no Soroban authorization-entry signing. Anything this could\n * return instead of an error would be a signature the network rejects, discovered\n * by the user rather than by the dapp.\n */\n public signAuthEntry(): Promise<{ signedAuthEntry: string; signerAddress?: string }> {\n return Promise.reject(\n kitError(`${this.productName} does not support the \"signAuthEntry\" function`, NOT_SUPPORTED),\n );\n }\n\n /**\n * The network the WALLET is on, which is the only one it will sign for. A dapp\n * that wants another network has to ask the user to switch, not ask the wallet to\n * pretend.\n */\n public async getNetwork(): Promise<{ network: string; networkPassphrase: string }> {\n const provider = await this.provider();\n const { network, networkPassphrase } = await provider.getNetwork();\n if (!networkPassphrase) throw kitError('The wallet returned no network.', -1);\n return { network, networkPassphrase };\n }\n}\n\n/**\n * The kit reads `code`, `message` and `ext` off whatever a module rejects with, and\n * its own modules reject with a plain object. This keeps the `Error` prototype (so\n * a stack survives and `instanceof Error` holds for anyone else who catches it)\n * while carrying the fields the kit looks for.\n */\nfunction kitError(message: string, code: number): Error & IKitError {\n return Object.assign(new Error(message), { code, message });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|