orbis1-sdk-rn 0.0.4 → 0.0.5
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/README.md +211 -32
- package/ios/Rgb.swift +57 -2
- package/lib/module/Orbis1SDK.js +10 -5
- package/lib/module/Orbis1SDK.js.map +1 -1
- package/lib/module/features/gas-free/GasFreeModule.js +2 -2
- package/lib/module/features/gas-free/GasFreeModule.js.map +1 -1
- package/lib/module/features/gas-free/types/GasFreeConfig.js +9 -9
- package/lib/module/features/gas-free/types/GasFreeConfig.js.map +1 -1
- package/lib/module/features/watch-tower/WatchTowerModule.js +2 -2
- package/lib/module/features/watch-tower/WatchTowerModule.js.map +1 -1
- package/lib/module/features/watch-tower/index.js +0 -1
- package/lib/module/features/watch-tower/index.js.map +1 -1
- package/lib/module/features/watch-tower/types/WatchTowerConfig.js +11 -1
- package/lib/module/features/watch-tower/types/WatchTowerConfig.js.map +1 -1
- package/lib/module/features/watch-tower/types/index.js +0 -2
- package/lib/module/features/watch-tower/types/index.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/IFeatureModule.js.map +1 -1
- package/lib/module/types/SDKConfig.js +28 -2
- package/lib/module/types/SDKConfig.js.map +1 -1
- package/lib/typescript/src/Orbis1SDK.d.ts.map +1 -1
- package/lib/typescript/src/features/gas-free/types/GasFreeConfig.d.ts +11 -6
- package/lib/typescript/src/features/gas-free/types/GasFreeConfig.d.ts.map +1 -1
- package/lib/typescript/src/features/watch-tower/index.d.ts +0 -1
- package/lib/typescript/src/features/watch-tower/index.d.ts.map +1 -1
- package/lib/typescript/src/features/watch-tower/types/WatchTowerConfig.d.ts +10 -2
- package/lib/typescript/src/features/watch-tower/types/WatchTowerConfig.d.ts.map +1 -1
- package/lib/typescript/src/features/watch-tower/types/index.d.ts +0 -1
- package/lib/typescript/src/features/watch-tower/types/index.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/IFeatureModule.d.ts +3 -0
- package/lib/typescript/src/types/IFeatureModule.d.ts.map +1 -1
- package/lib/typescript/src/types/SDKConfig.d.ts +31 -43
- package/lib/typescript/src/types/SDKConfig.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Orbis1SDK.ts +20 -5
- package/src/features/gas-free/GasFreeModule.ts +2 -2
- package/src/features/gas-free/types/GasFreeConfig.ts +12 -10
- package/src/features/watch-tower/WatchTowerModule.ts +2 -2
- package/src/features/watch-tower/index.ts +0 -1
- package/src/features/watch-tower/types/WatchTowerConfig.ts +14 -2
- package/src/features/watch-tower/types/index.ts +0 -1
- package/src/index.tsx +1 -1
- package/src/types/IFeatureModule.ts +3 -0
- package/src/types/SDKConfig.ts +54 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SDKConfig.d.ts","sourceRoot":"","sources":["../../../../src/types/SDKConfig.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"SDKConfig.d.ts","sourceRoot":"","sources":["../../../../src/types/SDKConfig.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
package/src/Orbis1SDK.ts
CHANGED
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
import { Wallet } from './core/Wallet';
|
|
10
10
|
import type { IFeatureModule } from './types/IFeatureModule';
|
|
11
11
|
import type { SDKConfig } from './types/SDKConfig';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
validateSDKConfig,
|
|
14
|
+
mergeWithDefaults,
|
|
15
|
+
Environment,
|
|
16
|
+
} from './types/SDKConfig';
|
|
13
17
|
import { Feature } from './types/Feature';
|
|
14
18
|
import { ConfigurationError } from './errors/ConfigurationError';
|
|
15
19
|
import { OrbisError, OrbisErrorCode } from './errors/OrbisError';
|
|
@@ -17,6 +21,7 @@ import { FeatureRegistry } from './utils/FeatureRegistry';
|
|
|
17
21
|
import { Logger, createLogger } from './utils/logger';
|
|
18
22
|
import { WatchTowerModule } from './features/watch-tower';
|
|
19
23
|
import { GasFreeModule } from './features/gas-free';
|
|
24
|
+
import { BitcoinNetwork } from './core/Interfaces';
|
|
20
25
|
|
|
21
26
|
/**
|
|
22
27
|
* Orbis1SDK class
|
|
@@ -55,13 +60,21 @@ export class Orbis1SDK {
|
|
|
55
60
|
|
|
56
61
|
// Initialize wallet from config (if enabled)
|
|
57
62
|
if (this.config.wallet?.enabled) {
|
|
63
|
+
// Determine network from environment
|
|
64
|
+
const network =
|
|
65
|
+
this.config.environment === Environment.MAINNET
|
|
66
|
+
? BitcoinNetwork.MAINNET
|
|
67
|
+
: BitcoinNetwork.TESTNET4;
|
|
68
|
+
|
|
58
69
|
this.wallet = new Wallet(this.config.wallet.keys, {
|
|
59
|
-
network
|
|
70
|
+
network,
|
|
60
71
|
supportedSchemas: this.config.wallet.supportedSchemas,
|
|
61
72
|
maxAllocationsPerUtxo: this.config.wallet.maxAllocationsPerUtxo,
|
|
62
73
|
vanillaKeychain: this.config.wallet.vanillaKeychain,
|
|
63
74
|
});
|
|
64
|
-
this.logger.info(
|
|
75
|
+
this.logger.info(
|
|
76
|
+
`Wallet initialized for ${this.config.environment} environment`
|
|
77
|
+
);
|
|
65
78
|
}
|
|
66
79
|
|
|
67
80
|
// Initialize feature registry
|
|
@@ -121,8 +134,9 @@ export class Orbis1SDK {
|
|
|
121
134
|
}
|
|
122
135
|
|
|
123
136
|
const gasFreeModule = new GasFreeModule({
|
|
124
|
-
name:
|
|
137
|
+
name: Feature.GAS_FREE,
|
|
125
138
|
enabled: true,
|
|
139
|
+
environment: this.config.environment,
|
|
126
140
|
apiKey: this.config.apiKey,
|
|
127
141
|
timeout: features.gasFree.timeout,
|
|
128
142
|
});
|
|
@@ -133,8 +147,9 @@ export class Orbis1SDK {
|
|
|
133
147
|
// Initialize Watch Tower feature
|
|
134
148
|
if (features?.watchTower?.enabled) {
|
|
135
149
|
const watchTowerModule = new WatchTowerModule({
|
|
136
|
-
name:
|
|
150
|
+
name: Feature.WATCH_TOWER,
|
|
137
151
|
enabled: true,
|
|
152
|
+
environment: this.config.environment,
|
|
138
153
|
apiKey: this.config.apiKey,
|
|
139
154
|
});
|
|
140
155
|
this.featureRegistry.register(Feature.WATCH_TOWER, watchTowerModule);
|
|
@@ -16,7 +16,7 @@ import type { IServiceClient } from './client/IServiceClient';
|
|
|
16
16
|
import { ConsignmentReader } from './consignment/ConsignmentReader';
|
|
17
17
|
import type { IConsignmentReader } from './consignment/IConsignmentReader';
|
|
18
18
|
import type { GasFreeConfig } from './types/GasFreeConfig';
|
|
19
|
-
import {
|
|
19
|
+
import { getGasFreeServiceUrl } from './types/GasFreeConfig';
|
|
20
20
|
|
|
21
21
|
import type {
|
|
22
22
|
GasFreeTransferRequest,
|
|
@@ -86,7 +86,7 @@ export class GasFreeModule implements IFeatureModule<GasFreeConfig> {
|
|
|
86
86
|
// Store logger (create child logger with module prefix)
|
|
87
87
|
this.logger = logger?.child('GasFree');
|
|
88
88
|
|
|
89
|
-
const serviceUrl =
|
|
89
|
+
const serviceUrl = getGasFreeServiceUrl(this.config.environment);
|
|
90
90
|
|
|
91
91
|
this.logger?.debug('Initializing with config', {
|
|
92
92
|
baseUrl: serviceUrl,
|
|
@@ -8,13 +8,15 @@
|
|
|
8
8
|
|
|
9
9
|
import { z } from 'zod';
|
|
10
10
|
import type { IFeatureConfig } from '../../../types/IFeatureModule';
|
|
11
|
+
import { Feature } from '../../../types/Feature';
|
|
12
|
+
import { Environment } from '../../../types/SDKConfig';
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Gas-Free feature configuration
|
|
14
16
|
*/
|
|
15
17
|
export interface GasFreeConfig extends IFeatureConfig {
|
|
16
18
|
/** Feature name (must be 'gasFree') */
|
|
17
|
-
name:
|
|
19
|
+
name: Feature.GAS_FREE;
|
|
18
20
|
|
|
19
21
|
/** Whether the feature is enabled */
|
|
20
22
|
enabled: boolean;
|
|
@@ -48,7 +50,7 @@ export interface GasFreeConfig extends IFeatureConfig {
|
|
|
48
50
|
* Zod schema for Gas-Free configuration validation
|
|
49
51
|
*/
|
|
50
52
|
export const GasFreeConfigSchema = z.object({
|
|
51
|
-
name: z.literal(
|
|
53
|
+
name: z.literal(Feature.GAS_FREE, {
|
|
52
54
|
errorMap: () => ({ message: 'Gas-Free config must have name "gasFree"' }),
|
|
53
55
|
}),
|
|
54
56
|
enabled: z.boolean(),
|
|
@@ -78,11 +80,6 @@ export const GasFreeConfigSchema = z.object({
|
|
|
78
80
|
headers: z.record(z.string()).optional(),
|
|
79
81
|
});
|
|
80
82
|
|
|
81
|
-
/**
|
|
82
|
-
* Default Gas-Free configuration (internal use)
|
|
83
|
-
*/
|
|
84
|
-
const DEFAULT_SERVICE_URL = 'http://localhost:3000';
|
|
85
|
-
|
|
86
83
|
/**
|
|
87
84
|
* Default Gas-Free configuration
|
|
88
85
|
*/
|
|
@@ -96,10 +93,15 @@ export const DEFAULT_GAS_FREE_CONFIG: Partial<GasFreeConfig> = {
|
|
|
96
93
|
};
|
|
97
94
|
|
|
98
95
|
/**
|
|
99
|
-
* Get the hardcoded service URL
|
|
96
|
+
* Get the hardcoded service URL as a function of environment
|
|
97
|
+
*
|
|
98
|
+
* @param environment - SDK environment (mainnet or testnet)
|
|
99
|
+
* @returns Service URL for the specified environment
|
|
100
100
|
*/
|
|
101
|
-
export function
|
|
102
|
-
return
|
|
101
|
+
export function getGasFreeServiceUrl(environment: Environment): string {
|
|
102
|
+
return environment === Environment.MAINNET
|
|
103
|
+
? 'https://gasfree.orbis1.io'
|
|
104
|
+
: 'https://gasfree-dev.orbis1.io';
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
/**
|
|
@@ -13,7 +13,7 @@ import type { IFeatureModule } from '../../types/IFeatureModule';
|
|
|
13
13
|
import type { Wallet } from '../../core/Wallet';
|
|
14
14
|
import type { Logger } from '../../utils/logger';
|
|
15
15
|
import type { WatchTowerConfig } from './types';
|
|
16
|
-
import {
|
|
16
|
+
import { getWatchTowerServiceUrl } from './types/WatchTowerConfig';
|
|
17
17
|
|
|
18
18
|
export class WatchTowerModule implements IFeatureModule<WatchTowerConfig> {
|
|
19
19
|
readonly name = 'watchTower' as const;
|
|
@@ -39,7 +39,7 @@ export class WatchTowerModule implements IFeatureModule<WatchTowerConfig> {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
this.client = axios.create({
|
|
42
|
-
baseURL:
|
|
42
|
+
baseURL: getWatchTowerServiceUrl(this.config.environment),
|
|
43
43
|
headers: {
|
|
44
44
|
'Content-Type': 'application/json',
|
|
45
45
|
'Authorization': `Bearer ${this.config.apiKey}`,
|
|
@@ -4,12 +4,24 @@
|
|
|
4
4
|
* @module features/watch-tower/types/WatchTowerConfig
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import type { Feature } from '../../../types/Feature';
|
|
7
8
|
import type { IFeatureConfig } from '../../../types/IFeatureModule';
|
|
9
|
+
import { Environment } from '../../../types/SDKConfig';
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Get the hardcoded service URL as a function of environment
|
|
13
|
+
*
|
|
14
|
+
* @param environment - SDK environment (mainnet or testnet)
|
|
15
|
+
* @returns Service URL for the specified environment
|
|
16
|
+
*/
|
|
17
|
+
export function getWatchTowerServiceUrl(environment: Environment): string {
|
|
18
|
+
return environment === Environment.MAINNET
|
|
19
|
+
? 'https://watchtower.orbis1.io'
|
|
20
|
+
: 'https://watchtower-dev.orbis1.io';
|
|
21
|
+
}
|
|
10
22
|
|
|
11
23
|
export interface WatchTowerConfig extends IFeatureConfig {
|
|
12
|
-
name:
|
|
24
|
+
name: Feature.WATCH_TOWER;
|
|
13
25
|
enabled: boolean;
|
|
14
26
|
apiKey: string;
|
|
15
27
|
}
|
package/src/index.tsx
CHANGED
|
@@ -15,7 +15,7 @@ export { Orbis1SDK } from './Orbis1SDK';
|
|
|
15
15
|
|
|
16
16
|
// Types
|
|
17
17
|
export type { SDKConfig } from './types/SDKConfig';
|
|
18
|
-
export { LogLevel } from './types/SDKConfig';
|
|
18
|
+
export { LogLevel, Environment } from './types/SDKConfig';
|
|
19
19
|
export { Feature, isValidFeature } from './types/Feature';
|
|
20
20
|
export type { IFeatureModule, IFeatureConfig } from './types/IFeatureModule';
|
|
21
21
|
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import type { Wallet } from '../core/Wallet';
|
|
11
11
|
import type { Logger } from '../utils/logger';
|
|
12
|
+
import { Environment } from './SDKConfig';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Base configuration type that all feature configs must extend
|
|
@@ -18,6 +19,8 @@ export interface IFeatureConfig {
|
|
|
18
19
|
name: string;
|
|
19
20
|
/** Whether the feature is enabled */
|
|
20
21
|
enabled: boolean;
|
|
22
|
+
/** SDK environment (testnet or mainnet) */
|
|
23
|
+
environment: Environment;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
/**
|
package/src/types/SDKConfig.ts
CHANGED
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { z } from 'zod';
|
|
10
|
-
import type {
|
|
11
|
-
import type { Keys, BitcoinNetwork, AssetSchema } from '../core/Interfaces';
|
|
10
|
+
import type { Keys, AssetSchema } from '../core/Interfaces';
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Wallet configuration for the SDK
|
|
@@ -18,8 +17,6 @@ export interface WalletConfig {
|
|
|
18
17
|
enabled: boolean;
|
|
19
18
|
/** Wallet keys (mnemonic, xpubs, etc.) */
|
|
20
19
|
keys: Keys;
|
|
21
|
-
/** Bitcoin network */
|
|
22
|
-
network?: BitcoinNetwork;
|
|
23
20
|
/** Supported asset schemas */
|
|
24
21
|
supportedSchemas?: AssetSchema[];
|
|
25
22
|
/** Maximum allocations per UTXO */
|
|
@@ -46,11 +43,21 @@ export enum LogLevel {
|
|
|
46
43
|
VERBOSE = 'verbose',
|
|
47
44
|
}
|
|
48
45
|
|
|
46
|
+
/**
|
|
47
|
+
* SDK Environment
|
|
48
|
+
* Determines which network and service endpoints to use
|
|
49
|
+
*/
|
|
50
|
+
export enum Environment {
|
|
51
|
+
/** Testnet4 environment */
|
|
52
|
+
TESTNET = 'testnet',
|
|
53
|
+
/** Mainnet environment (production) */
|
|
54
|
+
MAINNET = 'mainnet',
|
|
55
|
+
}
|
|
56
|
+
|
|
49
57
|
/**
|
|
50
58
|
* Zod schema for Gas-Free feature configuration
|
|
51
59
|
*/
|
|
52
60
|
export const GasFreeFeatureConfigSchema = z.object({
|
|
53
|
-
name: z.literal('gasFree').optional(),
|
|
54
61
|
enabled: z.boolean().optional(),
|
|
55
62
|
timeout: z.number().int().positive('Timeout must be positive').optional(),
|
|
56
63
|
});
|
|
@@ -59,7 +66,6 @@ export const GasFreeFeatureConfigSchema = z.object({
|
|
|
59
66
|
* Zod schema for Watch Tower feature configuration
|
|
60
67
|
*/
|
|
61
68
|
export const WatchTowerFeatureConfigSchema = z.object({
|
|
62
|
-
name: z.literal('watchTower').optional(),
|
|
63
69
|
enabled: z.boolean().optional(),
|
|
64
70
|
pollingInterval: z
|
|
65
71
|
.number()
|
|
@@ -88,6 +94,7 @@ export const SDKOptionsSchema = z.object({
|
|
|
88
94
|
*/
|
|
89
95
|
export const SDKConfigSchema = z.object({
|
|
90
96
|
apiKey: z.string().min(1, 'API key is required'),
|
|
97
|
+
environment: z.nativeEnum(Environment).default(Environment.MAINNET),
|
|
91
98
|
features: z
|
|
92
99
|
.object({
|
|
93
100
|
gasFree: GasFreeFeatureConfigSchema.optional(),
|
|
@@ -109,9 +116,17 @@ export interface SDKConfig {
|
|
|
109
116
|
*/
|
|
110
117
|
apiKey: string;
|
|
111
118
|
|
|
119
|
+
/**
|
|
120
|
+
* SDK environment (testnet or mainnet).
|
|
121
|
+
* Determines which network and service endpoints to use.
|
|
122
|
+
* Defaults to mainnet if not specified.
|
|
123
|
+
*/
|
|
124
|
+
environment: Environment;
|
|
125
|
+
|
|
112
126
|
/**
|
|
113
127
|
* Wallet configuration.
|
|
114
128
|
* Required for RGB operations and wallet-dependent features (Gas-Free).
|
|
129
|
+
* Network (testnet4 or mainnet) is determined by the environment setting.
|
|
115
130
|
*/
|
|
116
131
|
wallet?: WalletConfig;
|
|
117
132
|
|
|
@@ -123,19 +138,23 @@ export interface SDKConfig {
|
|
|
123
138
|
*/
|
|
124
139
|
features?: {
|
|
125
140
|
/** Gas-Free feature configuration */
|
|
126
|
-
gasFree?:
|
|
141
|
+
gasFree?: {
|
|
142
|
+
/** Enable the feature */
|
|
143
|
+
enabled?: boolean;
|
|
127
144
|
/** Request timeout in milliseconds */
|
|
128
145
|
timeout?: number;
|
|
129
146
|
};
|
|
130
147
|
|
|
131
148
|
/** Watch-Tower feature configuration */
|
|
132
|
-
watchTower?:
|
|
149
|
+
watchTower?: {
|
|
150
|
+
/** Enable the feature */
|
|
151
|
+
enabled?: boolean;
|
|
133
152
|
/** Polling interval in milliseconds */
|
|
134
153
|
pollingInterval?: number;
|
|
135
154
|
};
|
|
136
155
|
|
|
137
156
|
/** Custom features */
|
|
138
|
-
[key: string]:
|
|
157
|
+
[key: string]: { enabled?: boolean; [key: string]: unknown } | undefined;
|
|
139
158
|
};
|
|
140
159
|
|
|
141
160
|
/**
|
|
@@ -161,6 +180,7 @@ export interface SDKConfig {
|
|
|
161
180
|
* Default SDK configuration
|
|
162
181
|
*/
|
|
163
182
|
export const DEFAULT_SDK_CONFIG: Partial<SDKConfig> = {
|
|
183
|
+
environment: Environment.MAINNET,
|
|
164
184
|
features: {},
|
|
165
185
|
logging: {
|
|
166
186
|
level: LogLevel.INFO,
|
|
@@ -191,6 +211,30 @@ export function validateSDKConfig(config: SDKConfig): void {
|
|
|
191
211
|
}
|
|
192
212
|
throw error;
|
|
193
213
|
}
|
|
214
|
+
|
|
215
|
+
// Validate API key prefix matches environment
|
|
216
|
+
const apiKey = config.apiKey;
|
|
217
|
+
const environment = config.environment ?? Environment.MAINNET;
|
|
218
|
+
|
|
219
|
+
if (environment === Environment.TESTNET) {
|
|
220
|
+
if (!apiKey.startsWith('pk_test')) {
|
|
221
|
+
throw new Error(
|
|
222
|
+
`API key mismatch: testnet environment requires a testnet API key (prefix: pk_test), but got a key with prefix: ${apiKey.substring(
|
|
223
|
+
0,
|
|
224
|
+
7
|
|
225
|
+
)}`
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
} else if (environment === Environment.MAINNET) {
|
|
229
|
+
if (!apiKey.startsWith('sk_live')) {
|
|
230
|
+
throw new Error(
|
|
231
|
+
`API key mismatch: mainnet environment requires a production API key (prefix: sk_live), but got a key with prefix: ${apiKey.substring(
|
|
232
|
+
0,
|
|
233
|
+
7
|
|
234
|
+
)}`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
194
238
|
}
|
|
195
239
|
|
|
196
240
|
/**
|
|
@@ -202,6 +246,7 @@ export function validateSDKConfig(config: SDKConfig): void {
|
|
|
202
246
|
export function mergeWithDefaults(config: SDKConfig): SDKConfig {
|
|
203
247
|
return {
|
|
204
248
|
...config,
|
|
249
|
+
environment: config.environment ?? Environment.MAINNET,
|
|
205
250
|
features: {
|
|
206
251
|
...DEFAULT_SDK_CONFIG.features,
|
|
207
252
|
...config.features,
|