Skip to content

Commit

Permalink
Merge pull request #324 from omnisat/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
hathbanger authored Feb 19, 2025
2 parents cf055fb + 270f5e1 commit 322d347
Show file tree
Hide file tree
Showing 38 changed files with 407 additions and 252 deletions.
9 changes: 9 additions & 0 deletions .github/.dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
- package-ecosystem: "pnpm" # Adjust for your package manager
directory: "/" # Directory where `package.json` is located
schedule:
interval: "daily"
target-branch: "dev" # Change this from "main" to "dev"
commit-message:
prefix: "deps"
76 changes: 35 additions & 41 deletions apps/demo.lasereyes.build/components/WalletCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
} from '@/components/ui/select'

const WalletCard = ({
wallet,
Expand All @@ -68,10 +68,10 @@ const WalletCard = ({
setSignedPsbt: (
psbt:
| {
signedPsbtHex: string
signedPsbtBase64: string
txId?: string
}
signedPsbtHex: string
signedPsbtBase64: string
txId?: string
}
| undefined
) => void
}) => {
Expand Down Expand Up @@ -105,7 +105,7 @@ const WalletCard = ({
send,
pushPsbt,
switchNetwork,
getMetaBalances
getMetaBalances,
} = useLaserEyes()

const [hasError, setHasError] = useState(false)
Expand All @@ -120,16 +120,22 @@ const WalletCard = ({
'Inscribed 100% clientside with Laser Eyes'
)

const [runes, setRunes] = useState<{
balance: string;
symbol: string;
name: string;
}[] | undefined>()
const [selectedRune, setSelectedRune] = useState<{
balance: string;
symbol: string;
name: string;
} | undefined>(undefined);
const [runes, setRunes] = useState<
| {
balance: string
symbol: string
name: string
}[]
| undefined
>()
const [selectedRune, setSelectedRune] = useState<
| {
balance: string
symbol: string
name: string
}
| undefined
>(undefined)
const [runeToAddress, setRuneToAddress] = useState<string>('')
const [runeAmount, setRuneAmount] = useState<string>('')

Expand Down Expand Up @@ -167,12 +173,12 @@ const WalletCard = ({
paymentAddress,
paymentPublicKey,
network as
| typeof MAINNET
| typeof TESTNET
| typeof TESTNET4
| typeof SIGNET
| typeof FRACTAL_MAINNET
| typeof FRACTAL_TESTNET
| typeof MAINNET
| typeof TESTNET
| typeof TESTNET4
| typeof SIGNET
| typeof FRACTAL_MAINNET
| typeof FRACTAL_TESTNET
)
.then((psbt) => {
if (psbt && psbt.toHex() !== unsigned) {
Expand Down Expand Up @@ -207,7 +213,7 @@ const WalletCard = ({

useEffect(() => {
if (address) {
getMetaBalances("runes").then(setRunes)
getMetaBalances('runes').then(setRunes)
setRuneToAddress(address)
}
}, [address])
Expand Down Expand Up @@ -435,15 +441,14 @@ const WalletCard = ({
}
}, [inscribe, inscriptionText, network])


const sendRune = async () => {
try {
if (!selectedRune) throw new Error('No rune selected')
if (!address) throw new Error('No address available')
if (!runeToAddress) throw new Error('No destination address provided')
if (!runeAmount) throw new Error('No amount specified')

const txid = await send("runes", {
const txid = await send('runes', {
fromAddress: address,
toAddress: runeToAddress,
amount: Number(runeAmount),
Expand Down Expand Up @@ -658,22 +663,15 @@ const WalletCard = ({

<div className={'border-b border-2 border-[#232225] w-full my-2'} />
<div className="flex flex-col w-full gap-2">

<Select
onValueChange={(value) => {
const rune = runes?.find((r) => r.symbol === value);
setSelectedRune(rune);
const rune = runes?.find((r) => r.symbol === value)
setSelectedRune(rune)
}}
disabled={
isMissingWallet ||
!isConnected
}
disabled={isMissingWallet || !isConnected}
>
<SelectTrigger
disabled={
isMissingWallet ||
!isConnected
}
disabled={isMissingWallet || !isConnected}
className={cn(
'w-full bg-[#232225] border-none disabled:text-[#737275] text-center',
''
Expand All @@ -694,11 +692,7 @@ const WalletCard = ({
</SelectContent>
</Select>
<Input
disabled={
isMissingWallet ||
!isConnected ||
!selectedRune
}
disabled={isMissingWallet || !isConnected || !selectedRune}
className={cn(
'w-full bg-[#232225] border-none disabled:text-[#737275] text-center',
''
Expand Down
2 changes: 1 addition & 1 deletion packages/lasereyes-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@omnisat/lasereyes-core",
"private": false,
"version": "0.0.61",
"version": "0.0.62-rc.4",
"type": "module",
"main": "./dist/index.umd.cjs",
"module": "./dist/index.js",
Expand Down
30 changes: 25 additions & 5 deletions packages/lasereyes-core/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { MapStore, WritableAtom, keepMount, listenKeys } from 'nanostores'
import { BTCSendArgs, Config, ContentType, NetworkType, Protocol, ProviderType, RuneSendArgs } from '../types'
import {
BTCSendArgs,
Config,
ContentType,
NetworkType,
Protocol,
ProviderType,
RuneSendArgs,
} from '../types'
import {
LEATHER,
MAGIC_EDEN,
Expand All @@ -18,7 +26,7 @@ import { WalletProvider } from './providers'
import UnisatProvider from './providers/unisat'
import { isBase64, isHex } from '../lib/utils'
import * as bitcoin from 'bitcoinjs-lib'
import { LaserEyesStoreType } from './types'
import { LaserEyesStoreType, SignMessageOptions } from './types'
import { triggerDOMShakeHack } from './utils'
import XVerseProvider from './providers/xverse'
import { WizzProvider } from './providers/wizz'
Expand Down Expand Up @@ -239,13 +247,23 @@ export class LaserEyesClient {
}
}

async signMessage(message: string, toSignAddress?: string) {
async signMessage(
message: string,
toSignAddressOrOptions?: string | SignMessageOptions
) {
let options: SignMessageOptions = {}
if (typeof toSignAddressOrOptions === 'string') {
options = { toSignAddress: toSignAddressOrOptions }
} else if (toSignAddressOrOptions) {
options = toSignAddressOrOptions
}

if (!this.$store.get().provider) return
if (this.$providerMap[this.$store.get().provider!]) {
try {
return await this.$providerMap[
this.$store.get().provider!
]?.signMessage(message, toSignAddress)
]?.signMessage(message, options)
} catch (error) {
if (error instanceof Error) {
if (error.message.toLowerCase().includes('not implemented')) {
Expand Down Expand Up @@ -406,7 +424,9 @@ export class LaserEyesClient {
}

const balances =
await this.$providerMap[this.$store.get().provider!]!.getMetaBalances(protocol)
await this.$providerMap[this.$store.get().provider!]!.getMetaBalances(
protocol
)
// TODO: Decide if we want to store these balances
// this.$store.setKey(`${protocol}Balances`, JSON.stringify(balances))
return balances
Expand Down
29 changes: 20 additions & 9 deletions packages/lasereyes-core/src/client/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { MapStore, WritableAtom } from 'nanostores'
import { LaserEyesStoreType } from '../types'
import { BTCSendArgs, Config, ContentType, NetworkType, Protocol, ProviderType, RuneSendArgs } from '../../types'
import {
BTCSendArgs,
Config,
ContentType,
NetworkType,
Protocol,
ProviderType,
RuneSendArgs,
} from '../../types'
import { LaserEyesClient } from '..'
import { inscribeContent } from '../../lib/inscribe'
import { broadcastTx, getBTCBalance } from '../../lib/helpers'
Expand Down Expand Up @@ -38,7 +46,7 @@ export abstract class WalletProvider {
this.initialize()
}

disconnect(): void { }
disconnect(): void {}

abstract initialize(): void

Expand Down Expand Up @@ -99,7 +107,10 @@ export abstract class WalletProvider {

abstract sendBTC(to: string, amount: number): Promise<string>

abstract signMessage(message: string, toSignAddress?: string): Promise<string>
abstract signMessage(
message: string,
options?: { toSignAddress?: string }
): Promise<string>

abstract signPsbt(
tx: string,
Expand All @@ -109,10 +120,10 @@ export abstract class WalletProvider {
broadcast?: boolean
): Promise<
| {
signedPsbtHex: string | undefined
signedPsbtBase64: string | undefined
txId?: string
}
signedPsbtHex: string | undefined
signedPsbtBase64: string | undefined
txId?: string
}
| undefined
>

Expand Down Expand Up @@ -151,7 +162,7 @@ export abstract class WalletProvider {
throw new Error('Unsupported network')
}

const runeArgs = sendArgs as RuneSendArgs;
const runeArgs = sendArgs as RuneSendArgs
if (!runeArgs.runeId || !runeArgs.amount || !runeArgs.toAddress) {
throw new Error('Missing required parameters')
}
Expand All @@ -165,7 +176,7 @@ export abstract class WalletProvider {
paymentPublicKey: this.$store.get().paymentPublicKey,
toAddress: runeArgs.toAddress,
signPsbt: this.signPsbt.bind(this),
network
network,
})
default:
throw new Error('Unsupported protocol')
Expand Down
15 changes: 11 additions & 4 deletions packages/lasereyes-core/src/client/providers/leather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { getBTCBalance, isMainnetNetwork } from '../../lib/helpers'
import { LEATHER, P2TR, P2WPKH } from '../../constants/wallets'
import { listenKeys, MapStore } from 'nanostores'
import { persistentMap } from '@nanostores/persistent'
import { LaserEyesStoreType } from '../types'
import { SIGNET, TESTNET, TESTNET4 } from '../../constants'
import { LaserEyesStoreType, SignMessageOptions } from '../types'
import { ECDSA, SIGNET, TESTNET, TESTNET4 } from '../../constants'
import { RpcErrorCode } from 'sats-connect'
import {
handleStateChangePersistence,
Expand Down Expand Up @@ -127,7 +127,7 @@ export default class LeatherProvider extends WalletProvider {
return
}
}

if (!this.library) throw new Error("Leather isn't installed")
const getAddressesResponse: LeatherRPCResponse =
await this.library.request('getAddresses')
Expand Down Expand Up @@ -190,7 +190,14 @@ export default class LeatherProvider extends WalletProvider {
}
}
}
async signMessage(message: string, toSignAddress?: string): Promise<string> {
async signMessage(
message: string,
options?: SignMessageOptions
): Promise<string> {
const toSignAddress = options?.toSignAddress
const protocol = options?.protocol
if (protocol === ECDSA)
throw new Error("Leather doesn't support ECDSA message signing")
const paymentType =
toSignAddress === this.$store.get().address ? P2TR : P2WPKH
if (
Expand Down
20 changes: 13 additions & 7 deletions packages/lasereyes-core/src/client/providers/magic-eden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import {
} from 'sats-connect'
import { WalletProvider } from '.'
import {
ECDSA,
getSatsConnectNetwork,
LaserEyesStoreType,
MAGIC_EDEN,
MAINNET,
NetworkType,
ProviderType,
SignMessageOptions,
} from '../..'
import {
findOrdinalsAddress,
Expand Down Expand Up @@ -226,10 +228,11 @@ export default class MagicEdenProvider extends WalletProvider {

async signMessage(
message: string,
toSignAddress?: string | undefined
options?: SignMessageOptions
): Promise<string> {
try {
const tempAddy = toSignAddress || this.$store.get().paymentAddress
const tempAddy =
options?.toSignAddress || this.$store.get().paymentAddress
let signedMessage: string = ''

await signMessage({
Expand All @@ -240,7 +243,10 @@ export default class MagicEdenProvider extends WalletProvider {
},
address: tempAddy,
message: message,
protocol: MessageSigningProtocols.BIP322,
protocol:
options?.protocol === ECDSA
? MessageSigningProtocols.ECDSA
: MessageSigningProtocols.BIP322,
},
onFinish: (response) => {
signedMessage = response
Expand All @@ -265,10 +271,10 @@ export default class MagicEdenProvider extends WalletProvider {
broadcast?: boolean | undefined
): Promise<
| {
signedPsbtHex: string | undefined
signedPsbtBase64: string | undefined
txId?: string | undefined
}
signedPsbtHex: string | undefined
signedPsbtBase64: string | undefined
txId?: string | undefined
}
| undefined
> {
console.log('signPsbt', psbtBase64, _finalize, broadcast)
Expand Down
Loading

0 comments on commit 322d347

Please sign in to comment.