@mnee/ts-sdk 1.0.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,251 @@
1
+ export type Environment = 'production' | 'sandbox';
2
+ export type SdkConfig = {
3
+ environment: Environment;
4
+ apiKey?: string;
5
+ };
6
+ export type MNEEFee = {
7
+ min: number;
8
+ max: number;
9
+ fee: number;
10
+ };
11
+ export type MNEEConfig = {
12
+ approver: string;
13
+ feeAddress: string;
14
+ burnAddress: string;
15
+ mintAddress: string;
16
+ fees: MNEEFee[];
17
+ decimals: number;
18
+ tokenId: string;
19
+ };
20
+ export type TxOperation = 'transfer' | 'burn' | 'deploy' | 'mint' | 'redeem';
21
+ export type MNEEUtxo = {
22
+ data: {
23
+ bsv21: {
24
+ amt: number;
25
+ dec: number;
26
+ icon: string;
27
+ id: string;
28
+ op: string;
29
+ sym: string;
30
+ };
31
+ cosign: {
32
+ address: string;
33
+ cosigner: string;
34
+ };
35
+ };
36
+ height: number;
37
+ idx: number;
38
+ outpoint: string;
39
+ owners: string[];
40
+ satoshis: number;
41
+ score: number;
42
+ script: string;
43
+ txid: string;
44
+ vout: number;
45
+ };
46
+ export type SignatureRequest = {
47
+ prevTxid: string;
48
+ outputIndex: number;
49
+ inputIndex: number;
50
+ satoshis: number;
51
+ address: string | string[];
52
+ script?: string;
53
+ sigHashType?: number;
54
+ csIdx?: number;
55
+ data?: unknown;
56
+ };
57
+ export type TransactionFormat = 'tx' | 'beef' | 'ef';
58
+ export type MNEEBalance = {
59
+ address: string;
60
+ amount: number;
61
+ decimalAmount: number;
62
+ };
63
+ export type SendMNEE = {
64
+ address: string;
65
+ amount: number;
66
+ };
67
+ export type GetSignatures = {
68
+ rawtx: string;
69
+ sigRequests: SignatureRequest[];
70
+ format?: TransactionFormat;
71
+ };
72
+ export type SignatureResponse = {
73
+ inputIndex: number;
74
+ sig: string;
75
+ pubKey: string;
76
+ sigHashType: number;
77
+ csIdx?: number;
78
+ };
79
+ export type MneeInscription = {
80
+ p: string;
81
+ op: string;
82
+ id: string;
83
+ amt: string;
84
+ metadata?: {
85
+ action?: 'mint' | 'redeem';
86
+ [key: string]: any;
87
+ };
88
+ };
89
+ export type ParsedCosigner = {
90
+ cosigner: string;
91
+ address: string;
92
+ };
93
+ export interface File {
94
+ hash: string;
95
+ size: number;
96
+ type: string;
97
+ content: number[];
98
+ }
99
+ export interface Inscription {
100
+ file?: File;
101
+ fields?: {
102
+ [key: string]: any;
103
+ };
104
+ parent?: string;
105
+ }
106
+ export type BalanceResponse = Array<{
107
+ address: string;
108
+ amt: number;
109
+ precised: number;
110
+ }>;
111
+ export type TransferResponse = {
112
+ ticketId?: string;
113
+ rawtx?: string;
114
+ };
115
+ export type TransferStatus = {
116
+ id: string;
117
+ tx_id: string;
118
+ tx_hex: string;
119
+ action_requested: 'transfer';
120
+ status: 'BROADCASTING' | 'SUCCESS' | 'MINED' | 'FAILED';
121
+ createdAt: string;
122
+ updatedAt: string;
123
+ errors: string | null;
124
+ };
125
+ export type TransferOptions = {
126
+ broadcast?: boolean;
127
+ callbackUrl?: string;
128
+ };
129
+ export type TransferWebhookResponse = {
130
+ id: string;
131
+ tx_id: string;
132
+ tx_hex: string;
133
+ action_requested: 'transfer';
134
+ callback_url: string;
135
+ status: 'SUCCESS' | 'BROADCASTING' | 'MINED' | 'FAILED';
136
+ createdAt: string;
137
+ updatedAt: string;
138
+ errors: string | null;
139
+ };
140
+ export interface TransferMultiOptions {
141
+ inputs: Array<{
142
+ txid: string;
143
+ vout: number;
144
+ wif: string;
145
+ }>;
146
+ recipients: SendMNEE[];
147
+ changeAddress?: string | Array<{
148
+ address: string;
149
+ amount: number;
150
+ }>;
151
+ }
152
+ export type MneeSync = {
153
+ txid: string;
154
+ outs: null;
155
+ height: number;
156
+ idx: number;
157
+ score: number;
158
+ rawtx: string;
159
+ senders: string[];
160
+ receivers: string[];
161
+ };
162
+ export type Counterparty = {
163
+ address: string;
164
+ amount: number;
165
+ };
166
+ export type TxStatus = 'confirmed' | 'unconfirmed';
167
+ export type TxType = 'send' | 'receive';
168
+ export type TxHistory = {
169
+ txid: string;
170
+ height: number;
171
+ status: TxStatus;
172
+ type: TxType;
173
+ amount: number;
174
+ counterparties: Counterparty[];
175
+ fee: number;
176
+ score: number;
177
+ };
178
+ export type TxHistoryResponse = {
179
+ address: string;
180
+ history: TxHistory[];
181
+ nextScore: number;
182
+ };
183
+ export type TxAddressAmount = {
184
+ address: string;
185
+ amount: number;
186
+ };
187
+ export type ParseTxResponse = {
188
+ txid: string;
189
+ environment: Environment;
190
+ type: TxOperation;
191
+ inputs: TxAddressAmount[];
192
+ outputs: TxAddressAmount[];
193
+ isValid: boolean;
194
+ inputTotal: string;
195
+ outputTotal: string;
196
+ };
197
+ export interface ParseOptions {
198
+ includeRaw?: boolean;
199
+ }
200
+ export interface ParseTxExtendedResponse extends ParseTxResponse {
201
+ raw?: {
202
+ txHex: string;
203
+ inputs: Array<{
204
+ txid: string;
205
+ vout: number;
206
+ scriptSig: string;
207
+ sequence: number;
208
+ satoshis: number;
209
+ address?: string;
210
+ tokenData?: any;
211
+ }>;
212
+ outputs: Array<{
213
+ value: number;
214
+ scriptPubKey: string;
215
+ address?: string;
216
+ tokenData?: any;
217
+ }>;
218
+ };
219
+ }
220
+ export interface AddressHistoryParams {
221
+ address: string;
222
+ fromScore?: number;
223
+ limit?: number;
224
+ order?: 'asc' | 'desc';
225
+ }
226
+ export interface ProcessedInput {
227
+ address?: string;
228
+ amount: number;
229
+ satoshis: number;
230
+ inscription?: MneeInscription | null;
231
+ cosigner?: ParsedCosigner;
232
+ }
233
+ export interface ProcessedOutput {
234
+ address?: string;
235
+ amount: number;
236
+ satoshis: number;
237
+ inscription?: MneeInscription | null;
238
+ cosigner?: ParsedCosigner;
239
+ }
240
+ export interface TxInputResponse {
241
+ inputs: ProcessedInput[];
242
+ total: bigint;
243
+ environment?: Environment;
244
+ type?: TxOperation;
245
+ }
246
+ export interface TxOutputResponse {
247
+ outputs: ProcessedOutput[];
248
+ total: bigint;
249
+ environment?: Environment;
250
+ type?: TxOperation;
251
+ }
@@ -0,0 +1,54 @@
1
+ import { LockingScript, type PrivateKey, type PublicKey, type Script, type ScriptTemplate, type Transaction, UnlockingScript } from "@bsv/sdk";
2
+ /**
3
+ * P2PKH (Pay To Public Key Hash) class implementing ScriptTemplate.
4
+ *
5
+ * This class provides methods to create Pay To Public Key Hash locking and unlocking scripts, including the unlocking of P2PKH UTXOs with the private key.
6
+ */
7
+ export default class CosignTemplate implements ScriptTemplate {
8
+ /**
9
+ * Creates a P2PKH locking script for a given public key hash or address string
10
+ *
11
+ * @param {number[] | string} userPKHash or address - An array or address representing the public key hash of the owning user.
12
+ * @param {PublicKey} approverPubKey - Public key of the approver.
13
+ * @returns {LockingScript} - A P2PKH locking script.
14
+ */
15
+ lock(userPKHash: string | number[], approverPubKey: PublicKey): LockingScript;
16
+ /**
17
+ * Creates a function that generates a P2PKH unlocking script along with its signature and length estimation.
18
+ *
19
+ * The returned object contains:
20
+ * 1. `sign` - A function that, when invoked with a transaction and an input index,
21
+ * produces an unlocking script suitable for a P2PKH locked output.
22
+ * 2. `estimateLength` - A function that returns the estimated length of the unlocking script in bytes.
23
+ *
24
+ * @param {PrivateKey} userPrivateKey - The private key used for signing the transaction.
25
+ * @param {'all'|'none'|'single'} signOutputs - The signature scope for outputs.
26
+ * @param {boolean} anyoneCanPay - Flag indicating if the signature allows for other inputs to be added later.
27
+ * @param {number} sourceSatoshis - Optional. The amount being unlocked. Otherwise the input.sourceTransaction is required.
28
+ * @param {Script} lockingScript - Optional. The lockinScript. Otherwise the input.sourceTransaction is required.
29
+ * @returns {Object} - An object containing the `sign` and `estimateLength` functions.
30
+ */
31
+ userUnlock(userPrivateKey: PrivateKey, signOutputs?: "all" | "none" | "single", anyoneCanPay?: boolean, sourceSatoshis?: number, lockingScript?: Script): {
32
+ sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
33
+ estimateLength: () => Promise<182>;
34
+ };
35
+ /**
36
+ * Creates a function that generates a P2PKH unlocking script along with its signature and length estimation.
37
+ *
38
+ * The returned object contains:
39
+ * 1. `sign` - A function that, when invoked with a transaction and an input index,
40
+ * produces an unlocking script suitable for a P2PKH locked output.
41
+ * 2. `estimateLength` - A function that returns the estimated length of the unlocking script in bytes.
42
+ *
43
+ * @param {PrivateKey} approverPrivateKey - The private key used for signing the transaction.
44
+ * @param {'all'|'none'|'single'} signOutputs - The signature scope for outputs.
45
+ * @param {boolean} anyoneCanPay - Flag indicating if the signature allows for other inputs to be added later.
46
+ * @param {number} sourceSatoshis - Optional. The amount being unlocked. Otherwise the input.sourceTransaction is required.
47
+ * @param {Script} lockingScript - Optional. The lockinScript. Otherwise the input.sourceTransaction is required.
48
+ * @returns {Object} - An object containing the `sign` and `estimateLength` functions.
49
+ */
50
+ unlock(approverPrivateKey: PrivateKey, userSigScript: Script, signOutputs?: "all" | "none" | "single", anyoneCanPay?: boolean, sourceSatoshis?: number, lockingScript?: Script): {
51
+ sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
52
+ estimateLength: () => Promise<182>;
53
+ };
54
+ }
@@ -0,0 +1,51 @@
1
+ import { Script } from '@bsv/sdk';
2
+ import { MNEEBalance, MNEEConfig, SdkConfig, MNEEUtxo, ParseTxResponse, ParseTxExtendedResponse, ParseOptions, SendMNEE, TransferMultiOptions, TxHistoryResponse, AddressHistoryParams, TransferResponse, TransferStatus, TransferOptions } from './mnee.types.js';
3
+ export declare class MNEEService {
4
+ private mneeApiKey;
5
+ private mneeConfig;
6
+ private mneeApi;
7
+ constructor(config: SdkConfig);
8
+ getCosignerConfig(): Promise<MNEEConfig>;
9
+ toAtomicAmount(amount: number): number;
10
+ fromAtomicAmount(amount: number): number;
11
+ private createInscription;
12
+ getUtxos(address: string | string[], page?: number, size?: number, order?: 'asc' | 'desc'): Promise<MNEEUtxo[]>;
13
+ private fetchRawTx;
14
+ private getSignatures;
15
+ getEnoughUtxos(address: string, totalAtomicTokenAmount: number): Promise<MNEEUtxo[]>;
16
+ getAllUtxos(address: string): Promise<MNEEUtxo[]>;
17
+ transfer(request: SendMNEE[], wif: string, transferOptions?: TransferOptions): Promise<TransferResponse>;
18
+ submitRawTx(rawtx: string, transferOptions?: TransferOptions): Promise<TransferResponse>;
19
+ getTxStatus(ticketId: string): Promise<TransferStatus>;
20
+ getBalance(address: string): Promise<MNEEBalance>;
21
+ getBalances(addresses: string[]): Promise<MNEEBalance[]>;
22
+ private processMneeValidation;
23
+ validateMneeTx(rawTx: string, request?: SendMNEE[]): Promise<boolean>;
24
+ private getMneeSyncs;
25
+ getRecentTxHistory(address: string, fromScore?: number, limit?: number, order?: 'asc' | 'desc'): Promise<TxHistoryResponse>;
26
+ getRecentTxHistories(params: AddressHistoryParams[]): Promise<TxHistoryResponse[]>;
27
+ /**
28
+ * Parses inscription data from a script
29
+ * @param script The script to parse
30
+ * @returns The parsed inscription data or null if invalid
31
+ */
32
+ private parseInscriptionData;
33
+ private determineEnvironment;
34
+ private determineTransactionType;
35
+ private processTransactionInputs;
36
+ private processTransactionOutputs;
37
+ private validateTransaction;
38
+ private buildParseResponse;
39
+ private parseTransaction;
40
+ parseTx(txid: string, options?: ParseOptions): Promise<ParseTxResponse | ParseTxExtendedResponse>;
41
+ parseTxFromRawTx(rawTxHex: string, options?: ParseOptions): Promise<ParseTxResponse | ParseTxExtendedResponse>;
42
+ parseInscription(script: Script): import("./mnee.types.js").Inscription | undefined;
43
+ parseCosignerScripts(scripts: Script[]): import("./mnee.types.js").ParsedCosigner[];
44
+ private validateUniqueInputs;
45
+ private addInputsToTransaction;
46
+ private calculateTransferMultiFee;
47
+ private addChangeOutputs;
48
+ private signAllInputs;
49
+ private validateTokenConservation;
50
+ transferMulti(options: TransferMultiOptions, transferOptions?: TransferOptions): Promise<TransferResponse>;
51
+ }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@mnee/ts-sdk",
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "version": "1.0.0",
7
+ "description": "Official typescript SDK of MNEE USD stablecoin",
8
+ "type": "module",
9
+ "source": "src/index.ts",
10
+ "main": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.cjs"
17
+ },
18
+ "import": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.modern.js"
21
+ },
22
+ "default": {
23
+ "types": "./dist/index.d.ts",
24
+ "default": "./dist/index.modern.js"
25
+ }
26
+ }
27
+ },
28
+ "module": "./dist/index.module.js",
29
+ "unpkg": "./dist/index.umd.js",
30
+ "scripts": {
31
+ "clean": "rm -rf dist",
32
+ "build": "npm run clean && microbundle --globals @bsv/sdk=bsv && npm pack",
33
+ "start": "node dist/index.modern.js",
34
+ "test": "echo \"Error: no test specified\" && exit 1",
35
+ "prepublishOnly": "npm run build"
36
+ },
37
+ "keywords": [
38
+ "mnee",
39
+ "bsv",
40
+ "blockchain",
41
+ "stablecoin",
42
+ "1satordinal"
43
+ ],
44
+ "author": "MNEE",
45
+ "license": "MIT",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/mnee-xyz/mnee.git"
49
+ },
50
+ "homepage": "https://docs.mnee.io",
51
+ "bugs": {
52
+ "url": "https://github.com/mnee-xyz/mnee/issues"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^22.14.0",
56
+ "microbundle": "^0.15.1",
57
+ "ts-node": "^10.9.2",
58
+ "tsx": "^4.19.3",
59
+ "typescript": "^5.4.5"
60
+ },
61
+ "dependencies": {
62
+ "@bsv/sdk": "^1.3.30",
63
+ "bip39": "^3.1.0"
64
+ }
65
+ }