Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglescode committed Jun 14, 2024
1 parent b0af813 commit ab2231a
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
import RunDemoButton from '../../../common/runDemoButton';
import RunDemoResult from '../../../common/runDemoResult';
import SectionTwoCol from '../../../common/sectionTwoCol';
import { getMeshWallet } from './common';
import { useState } from "react";
import Codeblock from "../../../ui/codeblock";
import Card from "../../../ui/card";
import RunDemoButton from "../../../common/runDemoButton";
import RunDemoResult from "../../../common/runDemoResult";
import SectionTwoCol from "../../../common/sectionTwoCol";
import { getMeshWallet } from "./common";

export default function GetChangeAddress() {
return (
Expand All @@ -25,6 +25,12 @@ function Left() {
address to return leftover assets during transaction creation back to
the connected wallet.
</p>
<p>Options:</p>
<ul>
<li>
<code>addressType</code> - "enterprise" | "base" = "base"
</li>
</ul>
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useState } from 'react';
import Codeblock from '../../../ui/codeblock';
import Card from '../../../ui/card';
import RunDemoButton from '../../../common/runDemoButton';
import RunDemoResult from '../../../common/runDemoResult';
import SectionTwoCol from '../../../common/sectionTwoCol';
import { getMeshWallet } from './common';
import { useState } from "react";
import Codeblock from "../../../ui/codeblock";
import Card from "../../../ui/card";
import RunDemoButton from "../../../common/runDemoButton";
import RunDemoResult from "../../../common/runDemoResult";
import SectionTwoCol from "../../../common/sectionTwoCol";
import { getMeshWallet } from "./common";

export default function GetUnusedAddresses() {
return (
Expand All @@ -31,6 +31,12 @@ function Left() {
example:
</p>
<Codeblock data={example} isJson={false} />
<p>Options:</p>
<ul>
<li>
<code>addressType</code> - "enterprise" | "base" = "base"
</li>
</ul>
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ function Left() {
Returns a list of used addresses controlled by the wallet. For example:
</p>
<Codeblock data={example} isJson={false} />
<p>Options:</p>
<ul>
<li>
<code>addressType</code> - "enterprise" | "base" = "base"
</li>
</ul>
</>
);
}
Expand Down
6 changes: 6 additions & 0 deletions apps/mesh-web/components/pages/apis/meshwallet/getUtxos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ function Left() {
the wallet. For example:
</p>
<Codeblock data={example} isJson={false} />
<p>Options:</p>
<ul>
<li>
<code>addressType</code> - "enterprise" | "base" = "base"
</li>
</ul>
</>
);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/mesh-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@headlessui/react": "2.0.4",
"@heroicons/react": "2.1.3",
"@meshsdk/contracts": "1.0.1",
"@meshsdk/core": "1.5.24",
"@meshsdk/core": "1.5.25",
"@meshsdk/react": "1.1.12",
"axios": "1.7.2",
"copy-to-clipboard": "3.3.3",
Expand Down
2 changes: 1 addition & 1 deletion apps/mesh-web/pages/guides/smart-contract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ import { Transaction, Data, BlockfrostProvider, resolveDataHash } from '@meshsdk
get the exact UTxO we are trying to spend. For this we will use
<code>BlockfrostProvider</code>, but you can use any provider that
Mesh supports, see{' '}
<a href="https://meshjs.dev/apis/providers">Providers</a>.
<a href="https://meshjs.dev/providers">Providers</a>.
</p>
<p>
Paste the following function right before your<code>return</code>{' '}
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"vitest": "1.6.0"
},
"peerDependencies": {
"@meshsdk/core": "1.5.24"
"@meshsdk/core": "1.5.25"
},
"dependencies": {
"@meshsdk/common": "1.0.0-alpha.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Rapidly build Web3 apps on the Cardano Blockchain.",
"homepage": "https://meshjs.dev",
"author": "MeshJS",
"version": "1.5.24",
"version": "1.5.25",
"license": "Apache-2.0",
"type": "module",
"repository": {
Expand Down
60 changes: 34 additions & 26 deletions packages/core/src/wallet/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { csl } from '@mesh/core';
import { DEFAULT_PROTOCOL_PARAMETERS } from '@mesh/common/constants';
import { csl } from "@mesh/core";
import { DEFAULT_PROTOCOL_PARAMETERS } from "@mesh/common/constants";
import {
IFetcher,
IInitiator,
ISigner,
ISubmitter,
} from '@mesh/common/contracts';
import { mergeSignatures } from '@mesh/common/helpers';
} from "@mesh/common/contracts";
import { mergeSignatures } from "@mesh/common/helpers";
import {
deserializeTx,
toAddress,
toTxUnspentOutput,
} from '@mesh/common/utils';
import { EmbeddedWallet } from './embedded.service';
import type { Address, TransactionUnspentOutput } from '@mesh/core';
import type { DataSignature } from '@mesh/common/types';
} from "@mesh/common/utils";
import { EmbeddedWallet } from "./embedded.service";
import type { Address, TransactionUnspentOutput } from "@mesh/core";
import type { DataSignature } from "@mesh/common/types";

const DEFAULT_PASSWORD = 'MARI0TIME';
const DEFAULT_PASSWORD = "MARI0TIME";

export type AppWalletKeyType =
| {
type: 'root';
type: "root";
bech32: string;
}
| {
type: 'cli';
type: "cli";
payment: string;
stake?: string;
}
| {
type: 'mnemonic';
type: "mnemonic";
words: string[];
};

Expand All @@ -50,24 +50,24 @@ export class AppWallet implements IInitiator, ISigner, ISubmitter {
this._submitter = options.submitter;

switch (options.key.type) {
case 'mnemonic':
case "mnemonic":
this._wallet = new EmbeddedWallet(
options.networkId,
EmbeddedWallet.encryptMnemonic(options.key.words, DEFAULT_PASSWORD)
);
break;
case 'root':
case "root":
this._wallet = new EmbeddedWallet(
options.networkId,
EmbeddedWallet.encryptPrivateKey(options.key.bech32, DEFAULT_PASSWORD)
);
break;
case 'cli':
case "cli":
this._wallet = new EmbeddedWallet(
options.networkId,
EmbeddedWallet.encryptSigningKeys(
options.key.payment,
options.key.stake ?? 'f0'.repeat(34),
options.key.stake ?? "f0".repeat(34),
DEFAULT_PASSWORD
)
);
Expand Down Expand Up @@ -113,18 +113,23 @@ export class AppWallet implements IInitiator, ISigner, ISubmitter {
getUsedCollateral(
_limit = DEFAULT_PROTOCOL_PARAMETERS.maxCollateralInputs
): Promise<TransactionUnspentOutput[]> {
throw new Error('getUsedCollateral not implemented.');
throw new Error("getUsedCollateral not implemented.");
}

async getUsedUTxOs(accountIndex = 0): Promise<TransactionUnspentOutput[]> {
async getUsedUTxOs(
accountIndex = 0,
addressType: "enterprise" | "base" = "base"
): Promise<TransactionUnspentOutput[]> {
if (!this._fetcher) {
throw new Error(
'[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher.'
"[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher."
);
}
const account = this._wallet.getAccount(accountIndex, DEFAULT_PASSWORD);
const utxos = await this._fetcher.fetchAddressUTxOs(
account.enterpriseAddress
addressType == "enterprise"
? account.enterpriseAddress
: account.baseAddress
);

return utxos.map((utxo) => toTxUnspentOutput(utxo));
Expand Down Expand Up @@ -155,18 +160,21 @@ export class AppWallet implements IInitiator, ISigner, ISubmitter {
unsignedTx: string,
partialSign = false,
accountIndex = 0,
keyIndex = 0
keyIndex = 0,
addressType: "enterprise" | "base" = "base"
): Promise<string> {
try {
if (!this._fetcher) {
throw new Error(
'[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher.'
"[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher."
);
}
const account = this._wallet.getAccount(accountIndex, DEFAULT_PASSWORD);

const utxos = await this._fetcher.fetchAddressUTxOs(
account.enterpriseAddress
addressType == "enterprise"
? account.enterpriseAddress
: account.baseAddress
);

const newSignatures = this._wallet.signTx(
Expand Down Expand Up @@ -246,14 +254,14 @@ export class AppWallet implements IInitiator, ISigner, ISubmitter {
unsignedTxs: string[],
partialSign: boolean
): Promise<string[]> {
console.log('unimplemented', unsignedTxs, partialSign);
console.log("unimplemented", unsignedTxs, partialSign);
return [];
}

submitTx(tx: string): Promise<string> {
if (!this._submitter) {
throw new Error(
'[AppWallet] Submitter is required to submit transactions. Please provide a submitter.'
"[AppWallet] Submitter is required to submit transactions. Please provide a submitter."
);
}
return this._submitter.submitTx(tx);
Expand All @@ -272,7 +280,7 @@ export class AppWallet implements IInitiator, ISigner, ISubmitter {
}

async getCollateral() {
return (await this.getUsedUTxOs())[0]; // todo hinson
return (await this.getUsedUTxOs())[0];
}

async getUsedAddresses() {
Expand Down
Loading

0 comments on commit ab2231a

Please sign in to comment.