react-native-pirate-wallet 0.2.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-MIT +21 -0
- package/README.md +537 -0
- package/android/build.gradle +82 -0
- package/android/consumer-rules.pro +1 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/pirate/wallet/reactnative/PirateWalletReactNativeModule.kt +96 -0
- package/android/src/main/java/com/pirate/wallet/reactnative/PirateWalletReactNativePackage.kt +14 -0
- package/ios/PirateWalletReactNative.m +172 -0
- package/ios/PirateWalletReactNative.swift +40 -0
- package/package.json +64 -0
- package/react-native-pirate-wallet.podspec +19 -0
- package/react-native.config.js +10 -0
- package/scripts/assemble-ios-framework.js +124 -0
- package/scripts/resolve-android-packages.js +75 -0
- package/scripts/verify-package.js +128 -0
- package/src/index.d.ts +245 -0
- package/src/index.js +876 -0
- package/test/smoke.js +220 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const packageRoot = path.resolve(__dirname, '..');
|
|
7
|
+
|
|
8
|
+
function fail(message) {
|
|
9
|
+
console.error(`[react-native-pirate-wallet] ${message}`);
|
|
10
|
+
process.exitCode = 1;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function requireFile(relativePath) {
|
|
14
|
+
const absolutePath = path.join(packageRoot, relativePath);
|
|
15
|
+
if (!fs.statSync(absolutePath, {throwIfNoEntry: false})?.isFile()) {
|
|
16
|
+
fail(`Required package file is missing: ${relativePath}`);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (fs.statSync(absolutePath).size === 0) {
|
|
20
|
+
fail(`Required package file is empty: ${relativePath}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function rejectPath(relativePath) {
|
|
25
|
+
if (fs.existsSync(path.join(packageRoot, relativePath))) {
|
|
26
|
+
fail(`Generated build path must not be published: ${relativePath}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function collectFiles(directory) {
|
|
31
|
+
if (!fs.statSync(directory, {throwIfNoEntry: false})?.isDirectory()) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return fs.readdirSync(directory, {withFileTypes: true}).flatMap(entry => {
|
|
36
|
+
const entryPath = path.join(directory, entry.name);
|
|
37
|
+
return entry.isDirectory() ? collectFiles(entryPath) : [entryPath];
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const packageJson = JSON.parse(
|
|
42
|
+
fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
if (packageJson.name !== 'react-native-pirate-wallet') {
|
|
46
|
+
fail(`Unexpected package name: ${packageJson.name}`);
|
|
47
|
+
}
|
|
48
|
+
if (!/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(packageJson.version)) {
|
|
49
|
+
fail(`Package version is not valid semantic versioning: ${packageJson.version}`);
|
|
50
|
+
}
|
|
51
|
+
if (packageJson.private === true) {
|
|
52
|
+
fail('The publishable package must not be marked private');
|
|
53
|
+
}
|
|
54
|
+
if (packageJson.repository?.url !== 'https://github.com/PirateNetwork/Pirate-Unified-Light-Wallet.git') {
|
|
55
|
+
fail('The repository URL must match the GitHub repository used for npm provenance');
|
|
56
|
+
}
|
|
57
|
+
if (packageJson.publishConfig?.access !== 'public') {
|
|
58
|
+
fail('publishConfig.access must remain public');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
[
|
|
62
|
+
'LICENSE-MIT',
|
|
63
|
+
'README.md',
|
|
64
|
+
'react-native.config.js',
|
|
65
|
+
'react-native-pirate-wallet.podspec',
|
|
66
|
+
'scripts/assemble-ios-framework.js',
|
|
67
|
+
'scripts/resolve-android-packages.js',
|
|
68
|
+
'test/smoke.js',
|
|
69
|
+
'src/index.js',
|
|
70
|
+
'src/index.d.ts',
|
|
71
|
+
'android/src/main/AndroidManifest.xml',
|
|
72
|
+
'android/src/main/java/com/pirate/wallet/reactnative/PirateWalletReactNativeModule.kt',
|
|
73
|
+
'ios/PirateWalletReactNative.m',
|
|
74
|
+
'ios/PirateWalletReactNative.swift',
|
|
75
|
+
].forEach(requireFile);
|
|
76
|
+
|
|
77
|
+
if (process.argv.includes('--publish-layout')) {
|
|
78
|
+
[
|
|
79
|
+
'android/.gradle',
|
|
80
|
+
'android/build',
|
|
81
|
+
'android/src/main/jniLibs',
|
|
82
|
+
'ios/Frameworks/PirateWalletNative.xcframework',
|
|
83
|
+
].forEach(rejectPath);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const binaryPackageNames = [
|
|
87
|
+
'react-native-pirate-wallet-android',
|
|
88
|
+
'react-native-pirate-wallet-android-x86_64',
|
|
89
|
+
'react-native-pirate-wallet-ios-device',
|
|
90
|
+
'react-native-pirate-wallet-ios-simulator',
|
|
91
|
+
];
|
|
92
|
+
for (const binaryPackageName of binaryPackageNames) {
|
|
93
|
+
if (
|
|
94
|
+
packageJson.optionalDependencies?.[binaryPackageName] !== packageJson.version
|
|
95
|
+
) {
|
|
96
|
+
fail(`${binaryPackageName} must use the same exact version as the wrapper`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (
|
|
101
|
+
!process.argv.includes('--publish-layout') &&
|
|
102
|
+
(process.platform === 'darwin' || process.argv.includes('--all-platforms'))
|
|
103
|
+
) {
|
|
104
|
+
const staticLibraries = collectFiles(
|
|
105
|
+
path.join(packageRoot, 'ios', 'Frameworks', 'PirateWalletNative.xcframework'),
|
|
106
|
+
).filter(file => file.endsWith('.a'));
|
|
107
|
+
if (staticLibraries.length !== 2) {
|
|
108
|
+
fail('The iOS XCFramework must contain device and simulator static libraries');
|
|
109
|
+
}
|
|
110
|
+
for (const library of staticLibraries) {
|
|
111
|
+
if (fs.statSync(library).size === 0) {
|
|
112
|
+
fail(`The iOS static library is empty: ${path.relative(packageRoot, library)}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
const {resolveAndroidJniLibsPaths} = require('./resolve-android-packages');
|
|
119
|
+
if (resolveAndroidJniLibsPaths().length !== 2) {
|
|
120
|
+
fail('Both Android binary packages must resolve');
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
fail(error.message);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (process.exitCode) {
|
|
127
|
+
process.exit(process.exitCode);
|
|
128
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
export type SyncMode = 'Compact' | 'Deep'
|
|
2
|
+
export type SynchronizerStatus = 'STOPPED' | 'SYNCING' | 'SYNCED'
|
|
3
|
+
export type AmountString = string
|
|
4
|
+
export type AmountInput = AmountString | number | bigint
|
|
5
|
+
export type MnemonicLanguage =
|
|
6
|
+
| 'english'
|
|
7
|
+
| 'chinese_simplified'
|
|
8
|
+
| 'chinese_traditional'
|
|
9
|
+
| 'french'
|
|
10
|
+
| 'italian'
|
|
11
|
+
| 'japanese'
|
|
12
|
+
| 'korean'
|
|
13
|
+
| 'spanish'
|
|
14
|
+
|
|
15
|
+
export interface MnemonicInspection {
|
|
16
|
+
isValid: boolean
|
|
17
|
+
detectedLanguage: MnemonicLanguage | null
|
|
18
|
+
ambiguousLanguages: MnemonicLanguage[]
|
|
19
|
+
wordCount: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface WalletMeta {
|
|
23
|
+
id: string
|
|
24
|
+
name: string
|
|
25
|
+
createdAt: number
|
|
26
|
+
watchOnly: boolean
|
|
27
|
+
birthdayHeight: number
|
|
28
|
+
networkType?: 'mainnet' | 'testnet' | 'regtest' | null
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface SynchronizerConfig {
|
|
32
|
+
syncMode?: SyncMode
|
|
33
|
+
syncingPollIntervalMs?: number
|
|
34
|
+
syncedPollIntervalMs?: number
|
|
35
|
+
errorPollIntervalMs?: number
|
|
36
|
+
transactionLimit?: number | null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface PirateWalletAccountStorageConfig {
|
|
40
|
+
accountId: string
|
|
41
|
+
passphrase: string
|
|
42
|
+
storagePath?: string | null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface SynchronizerSnapshot {
|
|
46
|
+
walletId: string
|
|
47
|
+
alias: string
|
|
48
|
+
status: SynchronizerStatus
|
|
49
|
+
progressPercent: number
|
|
50
|
+
syncStatus: any
|
|
51
|
+
latestBirthdayHeight: number | null
|
|
52
|
+
balance: Balance | null
|
|
53
|
+
transactions: TransactionInfo[]
|
|
54
|
+
updatedAtMillis: number | null
|
|
55
|
+
lastError: Error | null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface SynchronizerCallbacks {
|
|
59
|
+
onStatusChanged?(event: { walletId: string; alias: string; name: SynchronizerStatus }): void
|
|
60
|
+
onUpdate?(snapshot: SynchronizerSnapshot): void
|
|
61
|
+
onError?(error: Error): void
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface PaymentDisclosure {
|
|
65
|
+
disclosureType: 'sapling' | 'ironwood' | string
|
|
66
|
+
txid: string
|
|
67
|
+
outputIndex: number
|
|
68
|
+
address: string
|
|
69
|
+
amount: AmountString
|
|
70
|
+
memo: string | null
|
|
71
|
+
disclosure: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface PaymentDisclosureVerification {
|
|
75
|
+
disclosureType: 'sapling' | 'ironwood' | string
|
|
76
|
+
txid: string
|
|
77
|
+
outputIndex: number
|
|
78
|
+
address: string
|
|
79
|
+
amount: AmountString
|
|
80
|
+
memo: string | null
|
|
81
|
+
memoHex: string
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface TransactionOutput {
|
|
85
|
+
addr: string
|
|
86
|
+
amount: AmountInput
|
|
87
|
+
memo?: string | null
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface Balance {
|
|
91
|
+
total: AmountString
|
|
92
|
+
spendable: AmountString
|
|
93
|
+
pending: AmountString
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface ShieldedPoolBalances {
|
|
97
|
+
sapling: Balance
|
|
98
|
+
ironwood: Balance
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface TransactionInfo {
|
|
102
|
+
txid: string
|
|
103
|
+
height: number | null
|
|
104
|
+
timestamp: number
|
|
105
|
+
amount: AmountString
|
|
106
|
+
fee: AmountString
|
|
107
|
+
memo: string | null
|
|
108
|
+
confirmed: boolean
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface TransactionRecipient {
|
|
112
|
+
address: string
|
|
113
|
+
pool: string
|
|
114
|
+
amount: AmountString
|
|
115
|
+
outputIndex: number
|
|
116
|
+
memo: string | null
|
|
117
|
+
paymentDisclosure?: string | null
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface TransactionDetails {
|
|
121
|
+
txid: string
|
|
122
|
+
height: number | null
|
|
123
|
+
timestamp: number
|
|
124
|
+
amount: AmountString
|
|
125
|
+
fee: AmountString
|
|
126
|
+
confirmed: boolean
|
|
127
|
+
memo: string | null
|
|
128
|
+
recipients: TransactionRecipient[]
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface PendingTransaction {
|
|
132
|
+
id: string
|
|
133
|
+
outputs: TransactionOutput[]
|
|
134
|
+
totalAmount: AmountString
|
|
135
|
+
fee: AmountString
|
|
136
|
+
change: AmountString
|
|
137
|
+
inputTotal: AmountString
|
|
138
|
+
numInputs: number
|
|
139
|
+
expiryHeight: number
|
|
140
|
+
createdAt: number
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface FeeInfo {
|
|
144
|
+
defaultFee: AmountString
|
|
145
|
+
minFee: AmountString
|
|
146
|
+
maxFee: AmountString
|
|
147
|
+
feePerOutput: AmountString
|
|
148
|
+
memoFeeMultiplier: number
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export class PirateWalletAdvancedKeyManagement {
|
|
152
|
+
listKeyGroups(walletId: string): Promise<any[]>
|
|
153
|
+
exportKeyGroupKeys(walletId: string, keyId: number): Promise<any>
|
|
154
|
+
importSpendingKey(
|
|
155
|
+
requestOrWalletId: any,
|
|
156
|
+
birthdayHeight?: number | null,
|
|
157
|
+
saplingSpendingKey?: string | null,
|
|
158
|
+
ironwoodSpendingKey?: string | null
|
|
159
|
+
): Promise<number>
|
|
160
|
+
exportSeed(walletId: string, mnemonicLanguage?: MnemonicLanguage | null): Promise<string>
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export class PirateWalletSynchronizer {
|
|
164
|
+
constructor(sdk: PirateWalletSdk, walletId: string, config?: SynchronizerConfig)
|
|
165
|
+
walletId: string
|
|
166
|
+
config: SynchronizerConfig
|
|
167
|
+
status: SynchronizerStatus
|
|
168
|
+
progress: number
|
|
169
|
+
syncStatus: any
|
|
170
|
+
latestBirthdayHeight: number | null
|
|
171
|
+
balance: any
|
|
172
|
+
transactions: any[]
|
|
173
|
+
lastError: Error | null
|
|
174
|
+
currentSnapshot(): SynchronizerSnapshot
|
|
175
|
+
isRunning(): boolean
|
|
176
|
+
isSyncing(): boolean
|
|
177
|
+
isComplete(): boolean
|
|
178
|
+
start(): Promise<void>
|
|
179
|
+
stop(): Promise<void>
|
|
180
|
+
refresh(): Promise<SynchronizerSnapshot>
|
|
181
|
+
close(): Promise<void>
|
|
182
|
+
subscribe(callbacks?: SynchronizerCallbacks): () => void
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export class PirateWalletSdk {
|
|
186
|
+
advancedKeyManagement: PirateWalletAdvancedKeyManagement
|
|
187
|
+
invoke(requestJson: string, pretty?: boolean): Promise<string>
|
|
188
|
+
configureAccountStorage(config: PirateWalletAccountStorageConfig): Promise<any>
|
|
189
|
+
createSynchronizer(walletId: string, config?: SynchronizerConfig): PirateWalletSynchronizer
|
|
190
|
+
buildInfoJson(pretty?: boolean): Promise<string>
|
|
191
|
+
buildInfo(): Promise<any>
|
|
192
|
+
walletRegistryExists(): Promise<boolean>
|
|
193
|
+
listWallets(): Promise<WalletMeta[]>
|
|
194
|
+
getActiveWalletId(): Promise<string | null>
|
|
195
|
+
getActiveWallet(): Promise<WalletMeta | null>
|
|
196
|
+
getWallet(walletId: string): Promise<WalletMeta | null>
|
|
197
|
+
createWallet(requestOrName: any, birthdayHeight?: number | null, mnemonicLanguage?: MnemonicLanguage | null): Promise<string>
|
|
198
|
+
restoreWallet(requestOrName: any, mnemonic?: string, birthdayHeight?: number | null, mnemonicLanguage?: MnemonicLanguage | null): Promise<string>
|
|
199
|
+
importViewingWallet(requestOrName: any, saplingViewingKey?: string | null, ironwoodViewingKey?: string | null, birthdayHeight?: number): Promise<string>
|
|
200
|
+
switchWallet(walletId: string): Promise<any>
|
|
201
|
+
renameWallet(walletId: string, newName: string): Promise<any>
|
|
202
|
+
deleteWallet(walletId: string): Promise<any>
|
|
203
|
+
setWalletBirthdayHeight(walletId: string, birthdayHeight: number): Promise<any>
|
|
204
|
+
getLatestBirthdayHeight(walletId: string): Promise<number | null>
|
|
205
|
+
generateMnemonic(wordCount?: number | null, mnemonicLanguage?: MnemonicLanguage | null): Promise<string>
|
|
206
|
+
validateMnemonic(mnemonic: string, mnemonicLanguage?: MnemonicLanguage | null): Promise<boolean>
|
|
207
|
+
inspectMnemonic(mnemonic: string): Promise<MnemonicInspection>
|
|
208
|
+
getNetworkInfo(): Promise<any>
|
|
209
|
+
isValidShieldedAddr(address: string): Promise<boolean>
|
|
210
|
+
validateAddress(address: string): Promise<any>
|
|
211
|
+
validateConsensusBranch(walletId: string): Promise<any>
|
|
212
|
+
formatAmount(arrrtoshis: AmountInput): Promise<string>
|
|
213
|
+
parseAmount(arrr: string): Promise<AmountString>
|
|
214
|
+
getCurrentReceiveAddress(walletId: string): Promise<string>
|
|
215
|
+
getCurrentAddress(walletId: string): Promise<string>
|
|
216
|
+
getNextReceiveAddress(walletId: string): Promise<string>
|
|
217
|
+
getNextAddress(walletId: string): Promise<string>
|
|
218
|
+
listAddresses(walletId: string): Promise<any[]>
|
|
219
|
+
listAddressBalances(walletId: string, keyId?: number | null): Promise<any[]>
|
|
220
|
+
getBalance(walletId: string): Promise<Balance>
|
|
221
|
+
getShieldedPoolBalances(walletId: string): Promise<ShieldedPoolBalances>
|
|
222
|
+
getSpendabilityStatus(walletId: string): Promise<any>
|
|
223
|
+
listTransactions(walletId: string, limit?: number | null): Promise<TransactionInfo[]>
|
|
224
|
+
fetchTransactionMemo(walletId: string, txId: string, outputIndex?: number | null): Promise<string | null>
|
|
225
|
+
getTransactionDetails(walletId: string, txId: string): Promise<TransactionDetails | null>
|
|
226
|
+
exportPaymentDisclosures(walletId: string, txId: string): Promise<PaymentDisclosure[]>
|
|
227
|
+
exportSaplingPaymentDisclosure(walletId: string, txId: string, outputIndex: number): Promise<string>
|
|
228
|
+
exportIronwoodPaymentDisclosure(walletId: string, txId: string, actionIndex: number): Promise<string>
|
|
229
|
+
verifyPaymentDisclosure(walletId: string, disclosure: string): Promise<PaymentDisclosureVerification>
|
|
230
|
+
getFeeInfo(): Promise<FeeInfo>
|
|
231
|
+
startSync(walletIdOrRequest: any, mode?: SyncMode): Promise<any>
|
|
232
|
+
getSyncStatus(walletId: string): Promise<any>
|
|
233
|
+
cancelSync(walletId: string): Promise<any>
|
|
234
|
+
rescan(walletIdOrRequest: any, fromHeight?: number | null): Promise<any>
|
|
235
|
+
buildTransaction(walletIdOrRequest: any, outputs?: TransactionOutput | TransactionOutput[] | null, fee?: AmountInput | null): Promise<PendingTransaction>
|
|
236
|
+
signTransaction(walletId: string, pending: PendingTransaction): Promise<any>
|
|
237
|
+
broadcastTransaction(signed: any): Promise<string>
|
|
238
|
+
send(walletId: string, outputsOrOutput: TransactionOutput | TransactionOutput[], fee?: AmountInput | null): Promise<string>
|
|
239
|
+
exportSaplingViewingKey(walletId: string): Promise<string>
|
|
240
|
+
exportIronwoodViewingKey(walletId: string): Promise<string>
|
|
241
|
+
importSaplingViewingKeyAsWatchOnly(requestOrName: any, saplingViewingKey?: string | null, birthdayHeight?: number | null): Promise<string>
|
|
242
|
+
getWatchOnlyCapabilities(walletId: string): Promise<any>
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function createPirateWalletSdk(): PirateWalletSdk
|