Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radix connects with the wrong address #969

Open
1 of 25 tasks
Rotwang9000 opened this issue Aug 30, 2024 · 4 comments
Open
1 of 25 tasks

Radix connects with the wrong address #969

Rotwang9000 opened this issue Aug 30, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@Rotwang9000
Copy link

Current behavior

Given a phrase or key, the address given for the Radix wallet gives a different address than that in other apps such as the Radix app or CacaoSwap.

`
export async function createPrivateKey(phrase: string) {
const seed = await mnemonicToSeed(phrase);

return new PrivateKey.Ed25519(seed.slice(0, 32));
}
`

Suspect it's to do with this... it should give a digest not just take the first 32 chars, although I've been unable so far to work out what it should be.

Unfortunately now I have some users (perhaps just one, but a big one) who has used this method and so it needs to be an optional change not a breaking one.

Expected behavior

Gives the same address as other things.

Functionality

  • Swap
  • Liquidity
  • Savers
  • Loan
  • Wallet
  • Transactions
  • Api
  • Other

Packages

  • @swapkit/sdk
  • @swapkit/core
  • @swapkit/api
  • @swapkit/helpers
  • @swapkit/tokens
  • @swapkit/toolbox-cosmos
  • @swapkit/toolbox-evm
  • @swapkit/toolbox-utxo
  • @swapkit/wallet-evm-extensions
  • @swapkit/wallet-keepkey
  • @swapkit/wallet-keplr
  • @swapkit/wallet-keystore
  • @swapkit/wallet-ledger
  • @swapkit/wallet-okx
  • @swapkit/wallet-trezor
  • @swapkit/wallet-wc
  • @swapkit/wallet-xdefi

Details

Package versions:
@swapkit/[email protected]

@Rotwang9000 Rotwang9000 added the bug Something isn't working label Aug 30, 2024
@Rotwang9000
Copy link
Author

Hope this helps.. as I say though, I'd like for the option of the current way to still be available.. perhaps if index is set to -1 or somehing then it could do that, otherwise, this...

`
import { generateMnemonic } from 'bip39';
import {
derivePath as deriveEd25519Path,
} from 'ed25519-hd-key'

	const { RadixEngineToolkit, PrivateKey, NetworkId } = await import(
		"@radixdlt/radix-engine-toolkit");


	const createRadixWallet = async (mnemonic, index = 0) => {

	
		let seed = mnemonicToSeedSync(mnemonic);
		const derivedKeys = deriveEd25519Path("m/44'/1022'/1'/525'/1460'/"+index+"'", seed)
		const privateKey = new PrivateKey.Ed25519(new Uint8Array(derivedKeys.key));
		const virtualAccountAddress = await RadixEngineToolkit.Derive.virtualAccountAddressFromPublicKey(
			privateKey.publicKey(),
			NetworkId.Mainnet
		);

		return {
			privateKey: privateKey,
			publicKey: privateKey.publicKeyHex(),
			address: virtualAccountAddress.toString(),
		};
	};

`

@towanTG
Copy link
Collaborator

towanTG commented Sep 3, 2024

Thanks will be working on radix in a couple hours.

@Rotwang9000
Copy link
Author

Thanks will be working on radix in a couple hours.

Cool... if you are doing other radix stuff, here is my code that can input into the maya LP.
Just needs a line changing and it can be used to send funds with a memo which the SimpleTransactionBuilder can't.

`
radixWallet.transfer = async function ({ assetValue, from, recipient, memo }) {

			const assetBigInt = bigInt(assetValue.bigIntValue / 1000000000000000000n);
			const assetNumber = assetBigInt.toJSNumber();

			const transactionHeader = {
				networkId: 1,
				validFromEpoch: Number(constructionMetadata.current_epoch),
				startEpochInclusive: Number(constructionMetadata.current_epoch),
				endEpochExclusive: Number(constructionMetadata.current_epoch) + 100,
				nonce: await generateRandomNonce(),
				fromAccount: from,
				signerPublicKey: signer.publicKey(),
				notaryPublicKey: signer.publicKey(),
				notaryIsSignatory: true,
				tipPercentage: 0
			};

			console.log('transactionHeader', transactionHeader);
			console.log('assetValue', assetValue);
			memo = memo + ':be:10';

			const mayaRouter = await mayaRadixRouter();


			console.log('assetBigInt', assetBigInt, decimal(assetNumber.toString()), assetNumber, address(from), address(recipient), memo);

			const transactionManifest = new ManifestBuilder()
				.callMethod(from, "lock_fee", [
					decimal(10),
				])
				.callMethod(from, "withdraw", [
					address(assetValue.address),
					decimal(assetNumber.toString()),
				])
				.takeAllFromWorktop(
					assetValue.address,
					 (builder, bucketId) => {
						console.log('bucketId', bucketId, bucket(bucketId), mayaRouter);

						return builder
							.callMethod(mayaRouter, "user_deposit", [
								address(from),
								address(recipient),
								bucket(bucketId),
								str(memo)
								
							])
					
					}
				)
				
				.build();
			console.log('transactionHeader', transactionHeader);
			console.log('transactionManifest', transactionManifest);


			const transaction = await TransactionBuilder.new()
				.then(builder =>
					builder
						.header(transactionHeader)
						.plainTextMessage(memo  || '') // Add the memo
						.manifest(transactionManifest)
						.sign(signer) // Sign the transaction
						.notarize(signer) // Notarize the transaction
				);

				console.log('transaction', transaction);

			const transactionId = await RadixEngineToolkit.NotarizedTransaction.intentHash(transaction);

			const compiledNotarizedTransaction =
				await RadixEngineToolkit.NotarizedTransaction.compile(transaction);

			console.log('transactionId', transactionId, compiledNotarizedTransaction);

			await radixWallet.api.LTS.submitTransaction({
				notarized_transaction_hex: Buffer.from(compiledNotarizedTransaction).toString('hex'),
			});
			return transactionId;
		};

`

@towanTG
Copy link
Collaborator

towanTG commented Sep 4, 2024

Today busy with hard fork - will be continuing tmrw. FYI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants
@towanTG @Rotwang9000 and others