mirror of
https://github.com/minibits-cash/minibits_wallet.git
synced 2026-10-06 11:48:24 +00:00
nostr-tools upgrade WIP
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "minibits_wallet",
|
||||
"version": "0.1.5-beta.26",
|
||||
"version": "0.1.6-beta",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"android:clean": "cd android && ./gradlew clean",
|
||||
@@ -36,7 +36,7 @@
|
||||
"mobx": "^6.9.0",
|
||||
"mobx-react-lite": "^3.4.3",
|
||||
"mobx-state-tree": "^5.1.8",
|
||||
"nostr-tools": "^1.17.0",
|
||||
"nostr-tools": "^2.1.4",
|
||||
"numbro": "^2.3.6",
|
||||
"patch-package": "^7.0.0",
|
||||
"postinstall-postinstall": "^2.1.0",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {Instance, SnapshotOut, types, flow} from 'mobx-state-tree'
|
||||
import {KeyChain, MinibitsClient, NostrClient, NostrUnsignedEvent, Wallet} from '../services'
|
||||
import {KeyChain, MinibitsClient, NostrClient, Wallet} from '../services'
|
||||
import { UnsignedEvent as NostrUnsignedEvent } from 'nostr-tools/core'
|
||||
import {log} from '../services/logService'
|
||||
import { Err } from '../utils/AppError'
|
||||
import { getRandomUsername } from '../utils/usernames'
|
||||
@@ -52,7 +53,8 @@ export const WalletProfileStoreModel = types
|
||||
name,
|
||||
picture,
|
||||
nip05,
|
||||
}),
|
||||
}),
|
||||
created_at: Math.floor(Date.now() / 1000)
|
||||
}
|
||||
|
||||
const rootStore = getRootStore(self)
|
||||
|
||||
@@ -43,7 +43,8 @@ import {
|
||||
import {TransactionStatus, Transaction} from '../models/Transaction'
|
||||
import {useStores} from '../models'
|
||||
import {useHeader} from '../utils/useHeader'
|
||||
import {Wallet, NostrClient, NostrProfile, KeyPair, NostrUnsignedEvent} from '../services'
|
||||
import {Wallet, NostrClient} from '../services'
|
||||
import { UnsignedEvent as NostrUnsignedEvent } from 'nostr-tools/core'
|
||||
import {log} from '../services/logService'
|
||||
import AppError, {Err} from '../utils/AppError'
|
||||
import {translate} from '../i18n'
|
||||
@@ -396,8 +397,9 @@ export const SendScreen: FC<WalletStackScreenProps<'Send'>> = observer(
|
||||
const dmEvent: NostrUnsignedEvent = {
|
||||
kind: 4,
|
||||
pubkey: senderPubkey,
|
||||
tags: [['p', receiverPubkey], ['from', walletProfileStore.nip05]],
|
||||
content: encryptedContent,
|
||||
tags: [['p', receiverPubkey as string], ['from', walletProfileStore.nip05]],
|
||||
content: encryptedContent,
|
||||
created_at: Math.floor(Date.now() / 1000)
|
||||
}
|
||||
|
||||
const sentEvent: Event | undefined = await NostrClient.publish(
|
||||
|
||||
@@ -34,7 +34,8 @@ import {
|
||||
import {TransactionStatus, Transaction} from '../models/Transaction'
|
||||
import {useStores} from '../models'
|
||||
import {useHeader} from '../utils/useHeader'
|
||||
import {NostrClient, NostrProfile, NostrUnsignedEvent, Wallet} from '../services'
|
||||
import {NostrClient, NostrProfile, Wallet} from '../services'
|
||||
import { UnsignedEvent as NostrUnsignedEvent } from 'nostr-tools/core'
|
||||
import {log} from '../services/logService'
|
||||
import AppError, { Err } from '../utils/AppError'
|
||||
|
||||
@@ -386,8 +387,9 @@ export const TopupScreen: FC<WalletStackScreenProps<'Topup'>> = observer(
|
||||
const dmEvent: NostrUnsignedEvent = {
|
||||
kind: 4,
|
||||
pubkey: senderPubkey,
|
||||
tags: [['p', receiverPubkey], ['from', walletProfileStore.nip05]],
|
||||
content: encryptedContent,
|
||||
tags: [['p', receiverPubkey as string], ['from', walletProfileStore.nip05]],
|
||||
content: encryptedContent,
|
||||
created_at: Math.floor(Date.now() / 1000)
|
||||
}
|
||||
|
||||
const sentEvent: Event | undefined = await NostrClient.publish(
|
||||
|
||||
@@ -2,10 +2,10 @@ import * as _Keychain from 'react-native-keychain'
|
||||
import AppError, {Err} from '../utils/AppError'
|
||||
import QuickCrypto from 'react-native-quick-crypto'
|
||||
import { generateNewMnemonic } from '@cashu/cashu-ts'
|
||||
import * as nostrTools from 'nostr-tools'
|
||||
import { generateSecretKey, getPublicKey } from 'nostr-tools/pure'
|
||||
import { bytesToHex } from '@noble/hashes/utils'
|
||||
import {btoa, atob, fromByteArray} from 'react-native-quick-base64'
|
||||
import {log} from './logService'
|
||||
import { createHash } from 'crypto'
|
||||
|
||||
|
||||
export enum KeyChainServiceName {
|
||||
@@ -213,8 +213,9 @@ const removeSeed = async function (): Promise<boolean> {
|
||||
|
||||
const generateNostrKeyPair = function () {
|
||||
try {
|
||||
const privateKey = nostrTools.generatePrivateKey() // hex string
|
||||
const publicKey = nostrTools.getPublicKey(privateKey)
|
||||
const privateKeyUint = generateSecretKey() // uintarr
|
||||
const publicKey = getPublicKey(privateKeyUint) // hex
|
||||
const privateKey = bytesToHex(privateKeyUint) // hex
|
||||
|
||||
log.trace('New HEX Nostr keypair created:', publicKey, privateKey)
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { finalizeEvent, verifyEvent } from 'nostr-tools/pure'
|
||||
import {
|
||||
nip19,
|
||||
getEventHash,
|
||||
@@ -8,7 +9,7 @@ import {
|
||||
validateEvent,
|
||||
UnsignedEvent as NostrUnsignedEvent,
|
||||
utils
|
||||
} from 'nostr-tools'
|
||||
} from 'nostr-tools/core'
|
||||
import QuickCrypto from 'react-native-quick-crypto'
|
||||
import {secp256k1} from '@noble/curves/secp256k1'
|
||||
import {
|
||||
@@ -20,13 +21,6 @@ import AppError, { Err } from '../utils/AppError'
|
||||
import { MinibitsClient } from './minibitsService'
|
||||
import { rootStoreInstance } from '../models'
|
||||
|
||||
export {
|
||||
Event as NostrEvent,
|
||||
Filter as NostrFilter,
|
||||
Kind as NostrKind,
|
||||
UnsignedEvent as NostrUnsignedEvent,
|
||||
} from 'nostr-tools'
|
||||
|
||||
// refresh
|
||||
export type NostrProfile = {
|
||||
pubkey: string
|
||||
@@ -50,8 +44,7 @@ export type Nip05VerificationRecord = {
|
||||
const _defaultPublicRelays: string[] = ['wss://relay.damus.io', 'wss://nostr.mom']
|
||||
const _minibitsRelays: string[] = [MINIBITS_RELAY_URL]
|
||||
let _pool: any = undefined
|
||||
const {relaysStore
|
||||
} = rootStoreInstance
|
||||
const {relaysStore} = rootStoreInstance
|
||||
|
||||
const getRelayPool = function () {
|
||||
if(!_pool) {
|
||||
@@ -174,25 +167,24 @@ const publish = async function (
|
||||
relays: string[],
|
||||
): Promise<Event | undefined> {
|
||||
|
||||
const keys: KeyPair = await getOrCreateKeyPair()
|
||||
const keys: KeyPair = await getOrCreateKeyPair()
|
||||
|
||||
event.created_at = Math.floor(Date.now() / 1000)
|
||||
event.id = getEventHash(event)
|
||||
event.sig = getSignature(event, keys.privateKey)
|
||||
let signedEvent = finalizeEvent(event, Uint8Array.from(Buffer.from(keys.privateKey, 'hex')))
|
||||
|
||||
if(!validateEvent(event)) {
|
||||
if(!validateEvent(signedEvent)) {
|
||||
throw new AppError(Err.VALIDATION_ERROR, 'Event is invalid and could not be published', event)
|
||||
}
|
||||
|
||||
log.trace('Event to be published', event, 'publish')
|
||||
log.trace('Event to be published', signedEvent, 'publish')
|
||||
|
||||
const pool = getRelayPool()
|
||||
let pubs = pool.publish(relays, event)
|
||||
let pubs = pool.publish(relays, signedEvent)
|
||||
|
||||
await delay(1000)
|
||||
// await Promise.all(pubs)
|
||||
|
||||
const published: NostrEvent = await pool.get(relays, {
|
||||
ids: [event.id]
|
||||
ids: [signedEvent.id]
|
||||
})
|
||||
|
||||
|
||||
|
||||
+4
-1
@@ -2,6 +2,9 @@
|
||||
"extends": "@tsconfig/react-native/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"jsx": "react",
|
||||
"typeRoots": ["./src/utils/envtypes"]
|
||||
"typeRoots": ["./src/utils/envtypes"],
|
||||
"paths": {
|
||||
"nostr-tools/*": ["./node_modules/nostr-tools/lib/types/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1611,12 +1611,12 @@
|
||||
resolved "https://registry.yarnpkg.com/@noble/ciphers/-/ciphers-0.2.0.tgz#a12cda60f3cf1ab5d7c77068c3711d2366649ed7"
|
||||
integrity sha512-6YBxJDAapHSdd3bLDv6x2wRPwq4QFMUaB3HvljNBUTThDd12eSm7/3F+2lnfzx2jvM+S6Nsy0jEt9QbPqSwqRw==
|
||||
|
||||
"@noble/curves@1.1.0", "@noble/curves@~1.1.0":
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.1.0.tgz#f13fc667c89184bc04cccb9b11e8e7bae27d8c3d"
|
||||
integrity sha512-091oBExgENk/kGj3AZmtBDMpxQPDtxQABR2B9lb1JbVTs6ytdzZNwvhxQ4MWasRNEzlbEH8jCWFCwhF/Obj5AA==
|
||||
"@noble/curves@1.2.0":
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35"
|
||||
integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==
|
||||
dependencies:
|
||||
"@noble/hashes" "1.3.1"
|
||||
"@noble/hashes" "1.3.2"
|
||||
|
||||
"@noble/curves@^1.0.0", "@noble/curves@~1.3.0":
|
||||
version "1.3.0"
|
||||
@@ -1625,11 +1625,23 @@
|
||||
dependencies:
|
||||
"@noble/hashes" "1.3.3"
|
||||
|
||||
"@noble/curves@~1.1.0":
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.1.0.tgz#f13fc667c89184bc04cccb9b11e8e7bae27d8c3d"
|
||||
integrity sha512-091oBExgENk/kGj3AZmtBDMpxQPDtxQABR2B9lb1JbVTs6ytdzZNwvhxQ4MWasRNEzlbEH8jCWFCwhF/Obj5AA==
|
||||
dependencies:
|
||||
"@noble/hashes" "1.3.1"
|
||||
|
||||
"@noble/hashes@1.3.1", "@noble/hashes@~1.3.1":
|
||||
version "1.3.1"
|
||||
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.1.tgz#8831ef002114670c603c458ab8b11328406953a9"
|
||||
integrity sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==
|
||||
|
||||
"@noble/hashes@1.3.2":
|
||||
version "1.3.2"
|
||||
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39"
|
||||
integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==
|
||||
|
||||
"@noble/hashes@1.3.3", "@noble/hashes@~1.3.0", "@noble/hashes@~1.3.2":
|
||||
version "1.3.3"
|
||||
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.3.tgz#39908da56a4adc270147bb07968bf3b16cfe1699"
|
||||
@@ -6270,17 +6282,24 @@ normalize-path@^3.0.0:
|
||||
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
|
||||
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
|
||||
|
||||
nostr-tools@^1.17.0:
|
||||
version "1.17.0"
|
||||
resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-1.17.0.tgz#b6f62e32fedfd9e68ec0a7ce57f74c44fc768e8c"
|
||||
integrity sha512-LZmR8GEWKZeElbFV5Xte75dOeE9EFUW/QLI1Ncn3JKn0kFddDKEfBbFN8Mu4TMs+L4HR/WTPha2l+PPuRnJcMw==
|
||||
nostr-tools@^2.1.4:
|
||||
version "2.1.4"
|
||||
resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-2.1.4.tgz#7df43a5279eb86ce0530420183620dc2618adaa7"
|
||||
integrity sha512-MX4gU1gJYP2PKdlLwveHhZIJi/k0qp+ZKwGB7gMFkUodJs4V1OX18Cteb+vxFngtD0B5LlCzLn+ml6tzwlKXFA==
|
||||
dependencies:
|
||||
"@noble/ciphers" "0.2.0"
|
||||
"@noble/curves" "1.1.0"
|
||||
"@noble/curves" "1.2.0"
|
||||
"@noble/hashes" "1.3.1"
|
||||
"@scure/base" "1.1.1"
|
||||
"@scure/bip32" "1.3.1"
|
||||
"@scure/bip39" "1.2.1"
|
||||
optionalDependencies:
|
||||
nostr-wasm v0.1.0
|
||||
|
||||
nostr-wasm@v0.1.0:
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/nostr-wasm/-/nostr-wasm-0.1.0.tgz#17af486745feb2b7dd29503fdd81613a24058d94"
|
||||
integrity sha512-78BTryCLcLYv96ONU8Ws3Q1JzjlAt+43pWQhIl86xZmWeegYCNLPml7yQ+gG3vR6V5h4XGj+TxO+SS5dsThQIA==
|
||||
|
||||
npm-run-path@^4.0.1:
|
||||
version "4.0.1"
|
||||
|
||||
Reference in New Issue
Block a user