@partylayer/core 0.2.2

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 CantonConnect
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
@@ -0,0 +1,255 @@
1
+ # @partylayer/core
2
+
3
+ <div align="center">
4
+
5
+ **Core types, errors, and abstractions for PartyLayer**
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@partylayer/core.svg?style=flat-square)](https://www.npmjs.com/package/@partylayer/core)
8
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg?style=flat-square)](https://www.typescriptlang.org/)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
10
+
11
+ </div>
12
+
13
+ ---
14
+
15
+ ## Overview
16
+
17
+ `@partylayer/core` provides the foundational types, error classes, and abstractions used by the PartyLayer SDK ecosystem. This package is primarily intended for:
18
+
19
+ - **Wallet adapter developers** building custom adapters
20
+ - **SDK contributors** working on the core SDK
21
+ - **Advanced users** who need direct access to types and utilities
22
+
23
+ > **Note**: Most dApp developers should use `@partylayer/sdk` instead, which re-exports the necessary types from this package.
24
+
25
+ ---
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ npm install @partylayer/core
31
+ ```
32
+
33
+ ---
34
+
35
+ ## What's Included
36
+
37
+ ### Type Definitions
38
+
39
+ ```typescript
40
+ import type {
41
+ // Branded types
42
+ WalletId,
43
+ PartyId,
44
+ SessionId,
45
+ NetworkId,
46
+ CapabilityKey,
47
+ Signature,
48
+ TransactionHash,
49
+
50
+ // Core types
51
+ WalletInfo,
52
+ Session,
53
+ SignedMessage,
54
+ SignedTransaction,
55
+ TxReceipt,
56
+ TransactionStatus,
57
+
58
+ // Adapter types
59
+ WalletAdapter,
60
+ AdapterContext,
61
+ AdapterDetectResult,
62
+ AdapterConnectResult,
63
+ SignMessageParams,
64
+ SignTransactionParams,
65
+ SubmitTransactionParams,
66
+
67
+ // Service adapters
68
+ StorageAdapter,
69
+ CryptoAdapter,
70
+ LoggerAdapter,
71
+ TelemetryAdapter,
72
+ } from '@partylayer/core';
73
+ ```
74
+
75
+ ### Error Classes
76
+
77
+ ```typescript
78
+ import {
79
+ PartyLayerError,
80
+ WalletNotFoundError,
81
+ WalletNotInstalledError,
82
+ UserRejectedError,
83
+ OriginNotAllowedError,
84
+ SessionExpiredError,
85
+ CapabilityNotSupportedError,
86
+ TransportError,
87
+ RegistryFetchFailedError,
88
+ RegistryVerificationFailedError,
89
+ RegistrySchemaInvalidError,
90
+ InternalError,
91
+ TimeoutError,
92
+ } from '@partylayer/core';
93
+ ```
94
+
95
+ ### Transport Classes
96
+
97
+ ```typescript
98
+ import {
99
+ PostMessageTransport,
100
+ DeepLinkTransport,
101
+ MockTransport,
102
+ } from '@partylayer/core';
103
+ ```
104
+
105
+ ### Utilities
106
+
107
+ ```typescript
108
+ import {
109
+ // Type constructors
110
+ toWalletId,
111
+ toPartyId,
112
+ toSessionId,
113
+ toNetworkId,
114
+ toSignature,
115
+ toTransactionHash,
116
+
117
+ // Guards
118
+ capabilityGuard,
119
+ installGuard,
120
+
121
+ // Error mapping
122
+ mapUnknownErrorToPartyLayerError,
123
+ } from '@partylayer/core';
124
+ ```
125
+
126
+ ---
127
+
128
+ ## Building a Wallet Adapter
129
+
130
+ If you're building a custom wallet adapter, implement the `WalletAdapter` interface:
131
+
132
+ ```typescript
133
+ import type {
134
+ WalletAdapter,
135
+ AdapterContext,
136
+ AdapterDetectResult,
137
+ AdapterConnectResult,
138
+ Session,
139
+ SignedMessage,
140
+ SignedTransaction,
141
+ SignMessageParams,
142
+ SignTransactionParams,
143
+ } from '@partylayer/core';
144
+ import { toWalletId, toSignature } from '@partylayer/core';
145
+
146
+ export class MyWalletAdapter implements WalletAdapter {
147
+ readonly walletId = toWalletId('my-wallet');
148
+ readonly name = 'My Wallet';
149
+
150
+ getCapabilities() {
151
+ return ['signMessage', 'signTransaction'] as const;
152
+ }
153
+
154
+ async detectInstalled(): Promise<AdapterDetectResult> {
155
+ const installed = typeof window !== 'undefined' &&
156
+ window.myWallet !== undefined;
157
+ return { installed };
158
+ }
159
+
160
+ async connect(
161
+ ctx: AdapterContext,
162
+ options: { timeoutMs: number }
163
+ ): Promise<AdapterConnectResult> {
164
+ // Implement connection logic
165
+ const result = await window.myWallet.connect();
166
+
167
+ return {
168
+ partyId: toPartyId(result.partyId),
169
+ capabilities: this.getCapabilities(),
170
+ session: {
171
+ expiresAt: Date.now() + 24 * 60 * 60 * 1000, // 24 hours
172
+ },
173
+ };
174
+ }
175
+
176
+ async disconnect(ctx: AdapterContext, session: Session): Promise<void> {
177
+ await window.myWallet.disconnect();
178
+ }
179
+
180
+ async signMessage(
181
+ ctx: AdapterContext,
182
+ session: Session,
183
+ params: SignMessageParams
184
+ ): Promise<SignedMessage> {
185
+ const sig = await window.myWallet.signMessage(params.message);
186
+ return {
187
+ message: params.message,
188
+ signature: toSignature(sig),
189
+ };
190
+ }
191
+
192
+ // Implement other methods...
193
+ }
194
+ ```
195
+
196
+ ---
197
+
198
+ ## Error Handling
199
+
200
+ All errors extend `PartyLayerError` and include an error code:
201
+
202
+ ```typescript
203
+ import {
204
+ PartyLayerError,
205
+ WalletNotInstalledError
206
+ } from '@partylayer/core';
207
+
208
+ try {
209
+ // ... wallet operation
210
+ } catch (error) {
211
+ if (error instanceof PartyLayerError) {
212
+ console.log('Error code:', error.code);
213
+ console.log('Message:', error.message);
214
+ console.log('Cause:', error.cause);
215
+ }
216
+ }
217
+ ```
218
+
219
+ ### Error Codes
220
+
221
+ | Error Class | Code |
222
+ |-------------|------|
223
+ | `WalletNotFoundError` | `WALLET_NOT_FOUND` |
224
+ | `WalletNotInstalledError` | `WALLET_NOT_INSTALLED` |
225
+ | `UserRejectedError` | `USER_REJECTED` |
226
+ | `OriginNotAllowedError` | `ORIGIN_NOT_ALLOWED` |
227
+ | `SessionExpiredError` | `SESSION_EXPIRED` |
228
+ | `CapabilityNotSupportedError` | `CAPABILITY_NOT_SUPPORTED` |
229
+ | `TransportError` | `TRANSPORT_ERROR` |
230
+ | `TimeoutError` | `TIMEOUT` |
231
+ | `InternalError` | `INTERNAL_ERROR` |
232
+
233
+ ---
234
+
235
+ ## Related Packages
236
+
237
+ | Package | Description |
238
+ |---------|-------------|
239
+ | [@partylayer/sdk](https://www.npmjs.com/package/@partylayer/sdk) | Main SDK for dApps |
240
+ | [@partylayer/react](https://www.npmjs.com/package/@partylayer/react) | React integration |
241
+ | [@partylayer/adapter-starter](https://www.npmjs.com/package/@partylayer/adapter-starter) | Template for new adapters |
242
+
243
+ ---
244
+
245
+ ## Links
246
+
247
+ - [GitHub Repository](https://github.com/cayvox/PartyLayer)
248
+ - [Wallet Provider Guide](https://github.com/cayvox/PartyLayer/blob/main/docs/wallet-provider-guide.md)
249
+ - [Report Issues](https://github.com/cayvox/PartyLayer/issues)
250
+
251
+ ---
252
+
253
+ ## License
254
+
255
+ MIT