diff --git a/cardano-wasm/examples/basic/example.js b/cardano-wasm/examples/basic/example.js index 1d9510bd49..cb120e67c9 100644 --- a/cardano-wasm/examples/basic/example.js +++ b/cardano-wasm/examples/basic/example.js @@ -48,7 +48,7 @@ async function do_async_work() { let PREVIEW_MAGIC_NUMBER = 2; let secretKey = "addr_sk1648253w4tf6fv5fk28dc7crsjsaw7d9ymhztd4favg3cwkhz7x8sl5u3ms"; - let wallet = await api.wallet.testnet.restoreTestnetPaymentWalletFromSigningKeyBech32(PREVIEW_MAGIC_NUMBER, secretKey); + let wallet = await api.wallet.testnet.restorePaymentWalletFromSigningKeyBech32(PREVIEW_MAGIC_NUMBER, secretKey); let bech32Address = await wallet.getAddressBech32(); log("Bech32 of address:"); diff --git a/cardano-wasm/examples/simple-wallet/example.js b/cardano-wasm/examples/simple-wallet/example.js index 6758b4f4ab..3ba05b55b2 100644 --- a/cardano-wasm/examples/simple-wallet/example.js +++ b/cardano-wasm/examples/simple-wallet/example.js @@ -11,7 +11,7 @@ async function do_async_work() { // State let showPrivateKey = false; - let wallet = await api.wallet.testnet.generateTestnetPaymentWallet(42); + let wallet = await api.wallet.testnet.generatePaymentWallet(42); let transactionInputs = []; let transactionOutputs = []; @@ -188,7 +188,7 @@ async function do_async_work() { // Callbacks async function generateAddress() { - wallet = await api.wallet.testnet.generateTestnetPaymentWallet(TESTNET_MAGIC); + wallet = await api.wallet.testnet.generatePaymentWallet(TESTNET_MAGIC); await refresh(); } @@ -205,7 +205,7 @@ async function do_async_work() { async function loadPrivateKey() { let pki = document.getElementById("private-key-input"); // @ts-ignore - wallet = await api.restoreTestnetPaymentWalletFromSigningKeyBech32(TESTNET_MAGIC, pki.value); + wallet = await api.wallet.testnet.restorePaymentWalletFromSigningKeyBech32(TESTNET_MAGIC, pki.value); await refresh(); }; diff --git a/cardano-wasm/lib-wrapper/cardano-api.d.ts b/cardano-wasm/lib-wrapper/cardano-api.d.ts index a9cae31b6e..40c38d7d74 100644 --- a/cardano-wasm/lib-wrapper/cardano-api.d.ts +++ b/cardano-wasm/lib-wrapper/cardano-api.d.ts @@ -90,14 +90,14 @@ declare interface CardanoApi { * @param networkMagic The network magic for the testnet. * @returns A promise that resolves to a new `Wallet` object. */ - generateTestnetPaymentWallet(networkMagic: number): Promise; + generatePaymentWallet(networkMagic: number): Promise; /** * Generate a stake wallet for testnet, given the testnet's network magic. * @param networkMagic The network magic for the testnet. * @returns A promise that resolves to a new `Wallet` object. */ - generateTestnetStakeWallet(networkMagic: number): Promise; + generateStakeWallet(networkMagic: number): Promise; /** * Restore a testnet payment wallet from a Bech32 encoded signing key. @@ -105,7 +105,7 @@ declare interface CardanoApi { * @param signingKeyBech32 The Bech32 encoded signing key. * @returns A promise that resolves to a new `Wallet` object. */ - restoreTestnetPaymentWalletFromSigningKeyBech32(networkMagic: number, signingKeyBech32: string): Promise; + restorePaymentWalletFromSigningKeyBech32(networkMagic: number, signingKeyBech32: string): Promise; /** * Restore a testnet stake wallet from Bech32 encoded signing keys. @@ -114,7 +114,7 @@ declare interface CardanoApi { * @param stakeSigningKeyBech32 The Bech32 encoded stake signing key. * @returns A promise that resolves to a new `Wallet` object. */ - restoreTestnetStakeWalletFromSigningKeyBech32(networkMagic: number, paymentSigningKeyBech32: string, stakeSigningKeyBech32: string): Promise; + restoreStakeWalletFromSigningKeyBech32(networkMagic: number, paymentSigningKeyBech32: string, stakeSigningKeyBech32: string): Promise; } } } diff --git a/cardano-wasm/lib-wrapper/main.js b/cardano-wasm/lib-wrapper/main.js index 9c6bd14ba9..a23a0f12c1 100644 --- a/cardano-wasm/lib-wrapper/main.js +++ b/cardano-wasm/lib-wrapper/main.js @@ -113,7 +113,7 @@ export function createInitializer(getWasi, loadWasmModule, createClient) { if (method.return.type === "fluent") { // Fluent methods are synchronous and update the provider // A fluent method is one that returns the same object type - target[method.name] = fixateArgs(method.params, function (...args) { + target[method.simpleName] = fixateArgs(method.params, function (...args) { const previousProvider = currentHaskellValueProvider; // We update the provider so that it resolves the previous provider and chains the next call currentHaskellValueProvider = async () => { @@ -124,7 +124,7 @@ export function createInitializer(getWasi, loadWasmModule, createClient) { }); } else { // Non-fluent methods (newObject or other) are async and apply the accumulated method calls - target[method.name] = fixateArgs(method.params, async function (...args) { + target[method.simpleName] = fixateArgs(method.params, async function (...args) { const haskellValue = await currentHaskellValueProvider(); // Resolve accumulated method calls const resultPromise = instance.exports[method.name](haskellValue, ...args); // Call the non-fluent method @@ -149,7 +149,7 @@ export function createInitializer(getWasi, loadWasmModule, createClient) { // Populate the main API object with static methods function populateStaticMethod(method, target) { - target[method.name] = async function (...args) { + target[method.simpleName] = async function (...args) { if (method.group) { if (!target[method.group]) { target[method.group] = {}; diff --git a/cardano-wasm/npm-wrapper/api.test.js b/cardano-wasm/npm-wrapper/api.test.js index 654f1264e8..1b64ec05d8 100644 --- a/cardano-wasm/npm-wrapper/api.test.js +++ b/cardano-wasm/npm-wrapper/api.test.js @@ -23,8 +23,8 @@ describe('Cardano API', () => { const outputAddress = "addr_test1vzpfxhjyjdlgk5c0xt8xw26avqxs52rtf69993j4tajehpcue4v2v"; // Restore wallet and verify the address - const wallet = await api.wallet.testnet.restoreTestnetPaymentWalletFromSigningKeyBech32(PREVIEW_MAGIC_NUMBER, secretKey); - + const wallet = await api.wallet.testnet.restorePaymentWalletFromSigningKeyBech32(PREVIEW_MAGIC_NUMBER, secretKey); + const bech32Address = await wallet.getAddressBech32(); expect(bech32Address).toBe(expectedAddress); diff --git a/cardano-wasm/src-lib/Cardano/Wasm/Api/Info.hs b/cardano-wasm/src-lib/Cardano/Wasm/Api/Info.hs index 2da549b401..699d1059cb 100644 --- a/cardano-wasm/src-lib/Cardano/Wasm/Api/Info.hs +++ b/cardano-wasm/src-lib/Cardano/Wasm/Api/Info.hs @@ -126,7 +126,9 @@ instance Aeson.ToJSON MethodGroup where -- | Information about a single method of a virtual object. data MethodInfo = MethodInfo { methodName :: String - -- ^ Name of the method in the virtual object of the JS API (which should match the exported function). + -- ^ Name of the global method name in the API (which should match the exported function and it must be unique globally). + , methodSimpleName :: String + -- ^ Name of the method in the virtual object of the API when accessed via JS (used for re-exporting to JS, may be shorter than methodName and does not need to be unique unlike methodName). , methodDoc :: String -- ^ General documentation for the method. , methodParams :: [ParamInfo] @@ -140,9 +142,10 @@ data MethodInfo = MethodInfo instance Aeson.ToJSON MethodInfo where toJSON :: MethodInfo -> Aeson.Value - toJSON (MethodInfo name doc params retType retDoc) = + toJSON (MethodInfo name simpleName doc params retType retDoc) = Aeson.object [ "name" Aeson..= name + , "simpleName" Aeson..= simpleName , "doc" Aeson..= doc , "params" Aeson..= params , "return" Aeson..= retType @@ -214,6 +217,7 @@ apiInfo = [ MethodInfoEntry $ MethodInfo { methodName = "getAddressBech32" + , methodSimpleName = "getAddressBech32" , methodDoc = "Get the Bech32 representation of the address. (Can be shared for receiving funds.)" , methodParams = [] , methodReturnType = OtherType TSString @@ -222,6 +226,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "getBech32ForPaymentVerificationKey" + , methodSimpleName = "getBech32ForPaymentVerificationKey" , methodDoc = "Get the Bech32 representation of the payment verification key of the wallet. (Can be shared for verification.)" , methodParams = [] @@ -231,6 +236,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "getBech32ForPaymentSigningKey" + , methodSimpleName = "getBech32ForPaymentSigningKey" , methodDoc = "Get the Bech32 representation of the payment signing key of the wallet. (Must be kept secret.)" , methodParams = [] @@ -240,6 +246,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "getBech32ForStakeVerificationKey" + , methodSimpleName = "getBech32ForStakeVerificationKey" , methodDoc = "Get the Bech32 representation of the stake verification key of the wallet. (Can be shared for verification.)" , methodParams = [] @@ -249,6 +256,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "getBech32ForStakeSigningKey" + , methodSimpleName = "getBech32ForStakeSigningKey" , methodDoc = "Get the Bech32 representation of the stake signing key of the wallet. (Must be kept secret.)" , methodParams = [] @@ -258,6 +266,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "getBase16ForPaymentVerificationKeyHash" + , methodSimpleName = "getBase16ForPaymentVerificationKeyHash" , methodDoc = "Get the base16 representation of the hash of the payment verification key of the wallet." , methodParams = [] @@ -267,6 +276,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "getBase16ForStakeVerificationKeyHash" + , methodSimpleName = "getBase16ForStakeVerificationKeyHash" , methodDoc = "Get the base16 representation of the hash of the stake verification key of the wallet." , methodParams = [] , methodReturnType = OtherType TSString @@ -283,6 +293,7 @@ apiInfo = [ MethodInfoEntry $ MethodInfo { methodName = "addTxInput" + , methodSimpleName = "addTxInput" , methodDoc = "Adds a simple transaction input to the transaction." , methodParams = [ ParamInfo "txId" TSString "The transaction ID of the input UTxO." @@ -294,6 +305,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "addSimpleTxOut" + , methodSimpleName = "addSimpleTxOut" , methodDoc = "Adds a simple transaction output to the transaction." , methodParams = [ ParamInfo "destAddr" TSString "The destination address." @@ -305,6 +317,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "setFee" + , methodSimpleName = "setFee" , methodDoc = "Sets the fee for the transaction." , methodParams = [ParamInfo "lovelaceAmount" TSBigInt "The fee amount in lovelaces."] , methodReturnType = Fluent @@ -313,6 +326,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "estimateMinFee" + , methodSimpleName = "estimateMinFee" , methodDoc = "Estimates the minimum fee for the transaction." , methodParams = [ ParamInfo "protocolParams" TSAny "The protocol parameters." @@ -329,6 +343,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "signWithPaymentKey" + , methodSimpleName = "signWithPaymentKey" , methodDoc = "Signs the transaction with a payment key." , methodParams = [ParamInfo "signingKey" TSString "The signing key to witness the transaction."] , methodReturnType = NewObject (virtualObjectName signedTxObj) @@ -345,6 +360,7 @@ apiInfo = [ MethodInfoEntry $ MethodInfo { methodName = "alsoSignWithPaymentKey" + , methodSimpleName = "alsoSignWithPaymentKey" , methodDoc = "Adds an extra signature to the transaction with a payment key." , methodParams = [ParamInfo "signingKey" TSString "The signing key to witness the transaction."] , methodReturnType = Fluent @@ -353,6 +369,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "txToCbor" + , methodSimpleName = "txToCbor" , methodDoc = "Converts the signed transaction to its CBOR representation." , methodParams = [] , methodReturnType = OtherType TSString @@ -370,6 +387,7 @@ apiInfo = [ MethodInfoEntry $ MethodInfo { methodName = "getEra" + , methodSimpleName = "getEra" , methodDoc = "Get the era from the Cardano Node using a GRPC-web client." , methodParams = [] , methodReturnType = OtherType TSNumber @@ -378,6 +396,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "submitTx" + , methodSimpleName = "submitTx" , methodDoc = "Submit a signed and CBOR-encoded transaction to the Cardano node." , methodParams = [ParamInfo "txCbor" TSString "The CBOR-encoded transaction as a hex string."] , methodReturnType = OtherType TSString @@ -386,6 +405,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "getProtocolParams" + , methodSimpleName = "getProtocolParams" , methodDoc = "Get the protocol parameters in the cardano-ledger format from the Cardano Node using a GRPC-web client." , methodParams = [] @@ -395,6 +415,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "getAllUtxos" + , methodSimpleName = "getAllUtxos" , methodDoc = "Get all UTXOs from the node using a GRPC-web client." , methodParams = [] @@ -406,6 +427,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "getUtxosForAddress" + , methodSimpleName = "getUtxosForAddress" , methodDoc = "Get UTXOs for a given address using a GRPC-web client." , methodParams = [ParamInfo "address" TSString "The address to get UTXOs for."] , methodReturnType = @@ -429,6 +451,7 @@ apiInfo = [ MethodInfoEntry $ MethodInfo { methodName = "newTx" + , methodSimpleName = "newTx" , methodDoc = "Create a new unsigned transaction in the current era " ++ getEraCommentForUnsignedTx (Just newTxImpl) @@ -440,6 +463,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "newExperimentalEraTx" + , methodSimpleName = "newExperimentalEraTx" , methodDoc = "Create a new unsigned transaction in the current experimental era " ++ getEraCommentForUnsignedTx newExperimentalEraTxImpl @@ -451,6 +475,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "newConwayTx" + , methodSimpleName = "newConwayTx" , methodDoc = "Create a new unsigned transaction in the Conway era." , methodParams = [] , methodReturnType = NewObject (virtualObjectName unsignedTxObj) @@ -461,6 +486,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "newGrpcConnection" + , methodSimpleName = "newGrpcConnection" , methodDoc = "Create a new client connection for communicating with a Cardano node through gRPC-web." , methodParams = [ParamInfo "webGrpcUrl" TSString "The URL of the gRPC-web server."] , methodReturnType = NewObject (virtualObjectName grpcConnection) @@ -479,6 +505,7 @@ apiInfo = [ MethodInfoEntry $ MethodInfo { methodName = "generatePaymentWallet" + , methodSimpleName = "generatePaymentWallet" , methodDoc = "Generate a simple payment wallet for mainnet." , methodParams = [] , methodReturnType = NewObject (virtualObjectName walletObj) @@ -487,6 +514,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "generateStakeWallet" + , methodSimpleName = "generateStakeWallet" , methodDoc = "Generate a stake wallet for mainnet." , methodParams = [] , methodReturnType = NewObject (virtualObjectName walletObj) @@ -495,6 +523,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "restorePaymentWalletFromSigningKeyBech32" + , methodSimpleName = "restorePaymentWalletFromSigningKeyBech32" , methodDoc = "Restore a mainnet payment wallet from a Bech32 encoded signing key." , methodParams = [ParamInfo "signingKeyBech32" TSString "The Bech32 encoded signing key."] , methodReturnType = NewObject (virtualObjectName walletObj) @@ -503,6 +532,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "restoreStakeWalletFromSigningKeyBech32" + , methodSimpleName = "restoreStakeWalletFromSigningKeyBech32" , methodDoc = "Restore a mainnet stake wallet from Bech32 encoded signing keys." , methodParams = [ ParamInfo "paymentSigningKeyBech32" TSString "The Bech32 encoded payment signing key." @@ -521,6 +551,7 @@ apiInfo = [ MethodInfoEntry $ MethodInfo { methodName = "generateTestnetPaymentWallet" + , methodSimpleName = "generatePaymentWallet" , methodDoc = "Generate a simple payment wallet for testnet, given the testnet's network magic." , methodParams = [ParamInfo "networkMagic" TSNumber "The network magic for the testnet."] , methodReturnType = NewObject (virtualObjectName walletObj) @@ -529,6 +560,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "generateTestnetStakeWallet" + , methodSimpleName = "generateStakeWallet" , methodDoc = "Generate a stake wallet for testnet, given the testnet's network magic." , methodParams = [ParamInfo "networkMagic" TSNumber "The network magic for the testnet."] , methodReturnType = NewObject (virtualObjectName walletObj) @@ -537,6 +569,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "restoreTestnetPaymentWalletFromSigningKeyBech32" + , methodSimpleName = "restorePaymentWalletFromSigningKeyBech32" , methodDoc = "Restore a testnet payment wallet from a Bech32 encoded signing key." , methodParams = [ ParamInfo "networkMagic" TSNumber "The network magic for the testnet." @@ -548,6 +581,7 @@ apiInfo = , MethodInfoEntry $ MethodInfo { methodName = "restoreTestnetStakeWalletFromSigningKeyBech32" + , methodSimpleName = "restoreStakeWalletFromSigningKeyBech32" , methodDoc = "Restore a testnet stake wallet from Bech32 encoded signing keys." , methodParams = [ ParamInfo "networkMagic" TSNumber "The network magic for the testnet." diff --git a/cardano-wasm/src-lib/Cardano/Wasm/Api/InfoToTypeScript.hs b/cardano-wasm/src-lib/Cardano/Wasm/Api/InfoToTypeScript.hs index a0334e2a24..2926ad9471 100644 --- a/cardano-wasm/src-lib/Cardano/Wasm/Api/InfoToTypeScript.hs +++ b/cardano-wasm/src-lib/Cardano/Wasm/Api/InfoToTypeScript.hs @@ -122,7 +122,7 @@ methodInfoToInterfaceContent selfTypeName method = <> ["@returns " <> Info.methodReturnDoc method] ) ( TypeScript.InterfaceMethod - (Info.methodName method) + (Info.methodSimpleName method) (map paramInfoToFunctionParam $ Info.methodParams method) (methodReturnTypeToString selfTypeName $ Info.methodReturnType method) )