Skip to content

Commit 1a91cb1

Browse files
authored
Merge pull request #949 from IntersectMBO/split-ts-into-multiple-files
Split TypeScript declaration files
2 parents a795554 + aaee7d9 commit 1a91cb1

12 files changed

Lines changed: 283 additions & 212 deletions

File tree

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ cardano-tracer/cardano-tracer-test
7777

7878
cardano-wasm/examples/*/cardano-wasm.wasm
7979
cardano-wasm/examples/*/cardano-wasm.js
80-
cardano-wasm/examples/*/cardano-api.d.ts
80+
cardano-wasm/examples/*/*.d.ts
8181
cardano-wasm/examples/*/cardano-api.js
8282
cardano-wasm/examples/*/cardano_node_grpc_web_pb.js
8383
.ghc-wasm/
8484

85-

cardano-wasm/app/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ parser =
2424
main :: IO ()
2525
main = do
2626
cmdArgs <- execParser (info (parser <**> helper) fullDesc)
27-
writeTypeScriptToDir (outputDir cmdArgs) (apiInfoToTypeScriptFile apiInfo)
27+
mapM_ (writeTypeScriptToDir (outputDir cmdArgs)) (apiInfoToTypeScriptFile apiInfo)

cardano-wasm/cardano-wasm.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ executable cardano-wasm
6161
cardano-crypto-class,
6262
cardano-ledger-api,
6363
cardano-strict-containers,
64+
casing,
6465
containers,
6566
exceptions,
6667
filepath,
Lines changed: 11 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,161 +1,10 @@
11
// cardano-api.d.ts
22

3-
export default initialise;
4-
5-
/**
6-
* Initialises the Cardano API.
7-
* @returns A promise that resolves to the main `CardanoApi` object.
8-
*/
9-
declare function initialise(): Promise<CardanoApi>;
3+
import UnsignedTx from './unsigned-tx';
104

11-
/**
12-
* Represents an unsigned transaction.
13-
*/
14-
declare interface UnsignedTx {
15-
/**
16-
* The type of the object, used for identification (the "UnsignedTx" string).
17-
*/
18-
objectType: string;
5+
import GrpcConnection from './grpc-connection';
196

20-
/**
21-
* Adds a simple transaction input to the transaction.
22-
* @param txId The transaction ID of the input UTxO.
23-
* @param txIx The index of the input within the UTxO.
24-
* @returns The `UnsignedTx` object with the added input.
25-
*/
26-
addTxInput(txId: string, txIx: number): UnsignedTx;
27-
28-
/**
29-
* Adds a simple transaction output to the transaction.
30-
* @param destAddr The destination address.
31-
* @param lovelaceAmount The amount in lovelaces to output.
32-
* @returns The `UnsignedTx` object with the added output.
33-
*/
34-
addSimpleTxOut(destAddr: string, lovelaceAmount: bigint): UnsignedTx;
35-
36-
/**
37-
* Sets the fee for the transaction.
38-
* @param lovelaceAmount The fee amount in lovelaces.
39-
* @returns The `UnsignedTx` object with the set fee.
40-
*/
41-
setFee(lovelaceAmount: bigint): UnsignedTx;
42-
43-
/**
44-
* Estimates the minimum fee for the transaction.
45-
* @param protocolParams The protocol parameters.
46-
* @param numKeyWitnesses The number of key witnesses.
47-
* @param numByronKeyWitnesses The number of Byron key witnesses.
48-
* @param totalRefScriptSize The total size of reference scripts in bytes.
49-
* @returns A promise that resolves to the estimated minimum fee in lovelaces.
50-
*/
51-
estimateMinFee(protocolParams: any, numKeyWitnesses: number, numByronKeyWitnesses: number, totalRefScriptSize: number): Promise<bigint>;
52-
53-
/**
54-
* Signs the transaction with a payment key.
55-
* @param signingKey The signing key to witness the transaction.
56-
* @returns A promise that resolves to a `SignedTx` object.
57-
*/
58-
signWithPaymentKey(signingKey: string): Promise<SignedTx>;
59-
}
60-
61-
/**
62-
* Represents a signed transaction.
63-
*/
64-
declare interface SignedTx {
65-
/**
66-
* The type of the object, used for identification (the "SignedTx" string).
67-
*/
68-
objectType: string;
69-
70-
/**
71-
* Adds an extra signature to the transaction with a payment key.
72-
* @param signingKey The signing key to witness the transaction.
73-
* @returns The `SignedTx` object with the additional signature.
74-
*/
75-
alsoSignWithPaymentKey(signingKey: string): SignedTx;
76-
77-
/**
78-
* Converts the signed transaction to its CBOR representation.
79-
* @returns A promise that resolves to the CBOR representation of the transaction as a hex string.
80-
*/
81-
txToCbor(): Promise<string>;
82-
}
83-
84-
/**
85-
* Represents a gRPC-web client connection to a Cardano node.
86-
*/
87-
declare interface GrpcConnection {
88-
/**
89-
* The type of the object, used for identification (the "GrpcConnection" string).
90-
*/
91-
objectType: string;
92-
93-
/**
94-
* Get the era from the Cardano Node using a GRPC-web client.
95-
* @returns A promise that resolves to the current era number.
96-
*/
97-
getEra(): Promise<number>;
98-
99-
/**
100-
* Submit a signed and CBOR-encoded transaction to the Cardano node.
101-
* @param txCbor The CBOR-encoded transaction as a hex string.
102-
* @returns A promise that resolves to the transaction ID.
103-
*/
104-
submitTx(txCbor: string): Promise<string>;
105-
106-
/**
107-
* Get the protocol parameters in the cardano-ledger format from the Cardano Node using a GRPC-web client.
108-
* @returns A promise that resolves to the current protocol parameters.
109-
*/
110-
getProtocolParams(): Promise<any>;
111-
112-
/**
113-
* Get all UTXOs from the node using a GRPC-web client.
114-
* @returns A promise that resolves to the current UTXO set.
115-
*/
116-
getAllUtxos(): Promise<{ address: string, txId: string, txIndex: number, lovelace: bigint, assets: any[], datum?: any, script?: any }[]>;
117-
118-
/**
119-
* Get UTXOs for a given address using a GRPC-web client.
120-
* @param address The address to get UTXOs for.
121-
* @returns A promise that resolves to the UTXOs for the given address.
122-
*/
123-
getUtxosForAddress(address: string): Promise<{ txId: string, txIndex: number, lovelace: bigint, assets: any[], datum?: any, script?: any }[]>;
124-
}
125-
126-
/**
127-
* Represents a wallet.
128-
*/
129-
declare interface Wallet {
130-
/**
131-
* The type of the object, used for identification (the "Wallet" string).
132-
*/
133-
objectType: string;
134-
135-
/**
136-
* Get the Bech32 representation of the address. (Can be shared for receiving funds.)
137-
* @returns The Bech32 representation of the address.
138-
*/
139-
getAddressBech32(): Promise<string>;
140-
141-
/**
142-
* Get the Bech32 representation of the verification key of the wallet. (Can be shared for verification.)
143-
* @returns The Bech32 representation of the verification key.
144-
*/
145-
getBech32ForVerificationKey(): Promise<string>;
146-
147-
/**
148-
* Get the Bech32 representation of the signing key of the wallet. (Must be kept secret.)
149-
* @returns The Bech32 representation of the signing key.
150-
*/
151-
getBech32ForSigningKey(): Promise<string>;
152-
153-
/**
154-
* Get the base16 representation of the hash of the verification key of the wallet.
155-
* @returns The base16 representation of the verification key hash.
156-
*/
157-
getBase16ForVerificationKeyHash(): Promise<string>;
158-
}
7+
import Wallet from './wallet';
1598

1609
/**
16110
* The main Cardano API object with static methods.
@@ -207,3 +56,11 @@ declare interface CardanoApi {
20756
*/
20857
restoreTestnetPaymentWalletFromSigningKeyBech32(networkMagic: number, signingKeyBech32: string): Promise<Wallet>;
20958
}
59+
60+
/**
61+
* Initialises the Cardano API.
62+
* @returns A promise that resolves to the main `CardanoApi` object.
63+
*/
64+
declare function initialise(): Promise<CardanoApi>;
65+
66+
export default initialise;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// grpc-connection.d.ts
2+
3+
/**
4+
* Represents a gRPC-web client connection to a Cardano node.
5+
*/
6+
declare interface GrpcConnection {
7+
/**
8+
* The type of the object, used for identification (the "GrpcConnection" string).
9+
*/
10+
objectType: string;
11+
12+
/**
13+
* Get the era from the Cardano Node using a GRPC-web client.
14+
* @returns A promise that resolves to the current era number.
15+
*/
16+
getEra(): Promise<number>;
17+
18+
/**
19+
* Submit a signed and CBOR-encoded transaction to the Cardano node.
20+
* @param txCbor The CBOR-encoded transaction as a hex string.
21+
* @returns A promise that resolves to the transaction ID.
22+
*/
23+
submitTx(txCbor: string): Promise<string>;
24+
25+
/**
26+
* Get the protocol parameters in the cardano-ledger format from the Cardano Node using a GRPC-web client.
27+
* @returns A promise that resolves to the current protocol parameters.
28+
*/
29+
getProtocolParams(): Promise<any>;
30+
31+
/**
32+
* Get all UTXOs from the node using a GRPC-web client.
33+
* @returns A promise that resolves to the current UTXO set.
34+
*/
35+
getAllUtxos(): Promise<{ address: string, txId: string, txIndex: number, lovelace: bigint, assets: any[], datum?: any, script?: any }[]>;
36+
37+
/**
38+
* Get UTXOs for a given address using a GRPC-web client.
39+
* @param address The address to get UTXOs for.
40+
* @returns A promise that resolves to the UTXOs for the given address.
41+
*/
42+
getUtxosForAddress(address: string): Promise<{ txId: string, txIndex: number, lovelace: bigint, assets: any[], datum?: any, script?: any }[]>;
43+
}
44+
45+
export default GrpcConnection;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// signed-tx.d.ts
2+
3+
/**
4+
* Represents a signed transaction.
5+
*/
6+
declare interface SignedTx {
7+
/**
8+
* The type of the object, used for identification (the "SignedTx" string).
9+
*/
10+
objectType: string;
11+
12+
/**
13+
* Adds an extra signature to the transaction with a payment key.
14+
* @param signingKey The signing key to witness the transaction.
15+
* @returns The `SignedTx` object with the additional signature.
16+
*/
17+
alsoSignWithPaymentKey(signingKey: string): SignedTx;
18+
19+
/**
20+
* Converts the signed transaction to its CBOR representation.
21+
* @returns A promise that resolves to the CBOR representation of the transaction as a hex string.
22+
*/
23+
txToCbor(): Promise<string>;
24+
}
25+
26+
export default SignedTx;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// unsigned-tx.d.ts
2+
3+
import SignedTx from './signed-tx';
4+
5+
/**
6+
* Represents an unsigned transaction.
7+
*/
8+
declare interface UnsignedTx {
9+
/**
10+
* The type of the object, used for identification (the "UnsignedTx" string).
11+
*/
12+
objectType: string;
13+
14+
/**
15+
* Adds a simple transaction input to the transaction.
16+
* @param txId The transaction ID of the input UTxO.
17+
* @param txIx The index of the input within the UTxO.
18+
* @returns The `UnsignedTx` object with the added input.
19+
*/
20+
addTxInput(txId: string, txIx: number): UnsignedTx;
21+
22+
/**
23+
* Adds a simple transaction output to the transaction.
24+
* @param destAddr The destination address.
25+
* @param lovelaceAmount The amount in lovelaces to output.
26+
* @returns The `UnsignedTx` object with the added output.
27+
*/
28+
addSimpleTxOut(destAddr: string, lovelaceAmount: bigint): UnsignedTx;
29+
30+
/**
31+
* Sets the fee for the transaction.
32+
* @param lovelaceAmount The fee amount in lovelaces.
33+
* @returns The `UnsignedTx` object with the set fee.
34+
*/
35+
setFee(lovelaceAmount: bigint): UnsignedTx;
36+
37+
/**
38+
* Estimates the minimum fee for the transaction.
39+
* @param protocolParams The protocol parameters.
40+
* @param numKeyWitnesses The number of key witnesses.
41+
* @param numByronKeyWitnesses The number of Byron key witnesses.
42+
* @param totalRefScriptSize The total size of reference scripts in bytes.
43+
* @returns A promise that resolves to the estimated minimum fee in lovelaces.
44+
*/
45+
estimateMinFee(protocolParams: any, numKeyWitnesses: number, numByronKeyWitnesses: number, totalRefScriptSize: number): Promise<bigint>;
46+
47+
/**
48+
* Signs the transaction with a payment key.
49+
* @param signingKey The signing key to witness the transaction.
50+
* @returns A promise that resolves to a `SignedTx` object.
51+
*/
52+
signWithPaymentKey(signingKey: string): Promise<SignedTx>;
53+
}
54+
55+
export default UnsignedTx;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// wallet.d.ts
2+
3+
/**
4+
* Represents a wallet.
5+
*/
6+
declare interface Wallet {
7+
/**
8+
* The type of the object, used for identification (the "Wallet" string).
9+
*/
10+
objectType: string;
11+
12+
/**
13+
* Get the Bech32 representation of the address. (Can be shared for receiving funds.)
14+
* @returns The Bech32 representation of the address.
15+
*/
16+
getAddressBech32(): Promise<string>;
17+
18+
/**
19+
* Get the Bech32 representation of the verification key of the wallet. (Can be shared for verification.)
20+
* @returns The Bech32 representation of the verification key.
21+
*/
22+
getBech32ForVerificationKey(): Promise<string>;
23+
24+
/**
25+
* Get the Bech32 representation of the signing key of the wallet. (Must be kept secret.)
26+
* @returns The Bech32 representation of the signing key.
27+
*/
28+
getBech32ForSigningKey(): Promise<string>;
29+
30+
/**
31+
* Get the base16 representation of the hash of the verification key of the wallet.
32+
* @returns The base16 representation of the verification key hash.
33+
*/
34+
getBase16ForVerificationKeyHash(): Promise<string>;
35+
}
36+
37+
export default Wallet;

0 commit comments

Comments
 (0)