Git Product home page Git Product logo

Comments (5)

sunbx avatar sunbx commented on August 15, 2024 1

@davidyuk Thank you for your answer. I will upgrade the contract to FATE V3. Then there will be no problem

from aepp-sdk-js.

nikita-fuchs avatar nikita-fuchs commented on August 15, 2024

@davidyuk should know !

from aepp-sdk-js.

davidyuk avatar davidyuk commented on August 15, 2024

AENS.transfer still works, but signature format changed since Ceres.

As far as we all in Ceres the best to use signDelegation method of Account or AeSdk.

The error you have is because aepp-calldata expects to get signature as hex string or Buffer, but sdk encodes it as sg_. So, you need to decode signature before passing to calldata. Related issue: aeternity/aepp-calldata-js#240

Here is example of changing name owner via delegation signature in Ceres using the [email protected]

import {
  Node, AeSdk, MemoryAccount, CompilerHttp, DelegationTag, packDelegation, decode,
} from '@aeternity/aepp-sdk';

const [owner, recipient] = [MemoryAccount.generate(), MemoryAccount.generate()];
console.log('Owner address', owner.address);
console.log('Recipient address', recipient.address);

const aeSdk = new AeSdk({
  accounts: [owner],
  nodes: [{ name: 'testnet', instance: new Node('https://testnet.aeternity.io') }],
  onCompiler: new CompilerHttp('https://v7.compiler.aepps.com'),
});

await fetch(`https://faucet.aepps.com/account/${owner.address}`, { method: 'POST' });

const name = `test-name-${Date.now()}.chain`;
await aeSdk.aensClaim(name, 0);
console.log('Claimed name', name);
console.log('Name owner', (await aeSdk.aensQuery(name)).owner);

const contractSourceCode = `
contract DelegateTest =
  stateful entrypoint transfer(
    owner: address, new_owner: address, name: string, sign: signature): unit =
    AENS.transfer(owner, new_owner, name, signature = sign)
`;
const contract = await aeSdk.initializeContract({ sourceCode: contractSourceCode });
const contractAddress = (await contract.$deploy([])).address;
console.log('Contract deployed at', contractAddress);

const delegation = packDelegation({
  tag: DelegationTag.AensName, accountAddress: aeSdk.address, contractAddress, nameId: name,
});
const delegationSignature = decode(await aeSdk.signDelegation(delegation));
await contract.transfer(owner.address, recipient.address, name, delegationSignature);
console.log('Name transferred');

console.log('Name owner', (await aeSdk.aensQuery(name)).owner);

from aepp-sdk-js.

sunbx avatar sunbx commented on August 15, 2024

I tried to use the method you provided to call, but still failed

Is there something wrong? I did not find it....

image

image

image

from aepp-sdk-js.

davidyuk avatar davidyuk commented on August 15, 2024

A private key exposed in the above message, ensure that you don't have much funds there!

I figured out the issue. Contracts deployed in Iris are executed in FATE v2, so it expects an old signature format. The problem is that we have security concerns about that format, and I would like to drop its support in future SDK versions. Is it feasible to migrate your contracts to FATE v3?

Meanwhile, you can provide consensusProtocolVersion: ConsensusProtocolVersion.Iris option to generate an old signature in Ceres using AeSdk::signNameDelegationToContract. See the below reproduction.

The code I've used to test it
import {
  Node, AeSdk, MemoryAccount, CompilerHttp, ConsensusProtocolVersion, decode,
} from '@aeternity/aepp-sdk';

const [owner, recipient] = [
  new MemoryAccount('9ebd7beda0c79af72a42ece3821a56eff16359b6df376cf049aee995565f022f840c974b97164776454ba119d84edc4d6058a8dec92b6edc578ab2d30b4c4200'),
  MemoryAccount.generate(),
];
console.log('Owner address', owner.address);
console.log('Recipient address', recipient.address);

const aeSdk = new AeSdk({
  accounts: [owner],
  nodes: [{ name: 'testnet', instance: new Node('http://localhost:3013') }],
  onCompiler: new CompilerHttp('https://v7.compiler.aepps.com'),
});

const contractSourceCode = `
contract DelegateTest =
  stateful entrypoint transfer(
    owner: address, new_owner: address, name: string, sign: signature): unit =
    AENS.transfer(owner, new_owner, name, signature = sign)
`;
const contract = await aeSdk.initializeContract({ sourceCode: contractSourceCode });
const contractAddress = (await contract.$deploy([])).address;
console.log('Contract deployed at', contractAddress);
console.log('Height', await aeSdk.getHeight());
console.log('Consensus', ConsensusProtocolVersion[(await aeSdk.api.getNodeInfo()).consensusProtocolVersion]);

const name = `test-name-${Date.now()}.chain`;
const nameObj = await aeSdk.aensPreclaim(name);
await nameObj.claim();
console.log('Claimed name', name);
console.log('Name owner', (await aeSdk.aensQuery(name)).owner);

console.log('Height', await aeSdk.getHeight());
console.log('Consensus', ConsensusProtocolVersion[(await aeSdk.api.getNodeInfo()).consensusProtocolVersion]);
const delegationSignature = await aeSdk.signNameDelegationToContract(
  contractAddress,
  name,
  { consensusProtocolVersion: ConsensusProtocolVersion.Iris },
);
console.log('delegationSignature', delegationSignature);
const delegationSignatureAsHex = decode(delegationSignature);
await contract.transfer(owner.address, recipient.address, name, delegationSignatureAsHex);
console.log('Name transferred');

console.log('Name owner', (await aeSdk.aensQuery(name)).owner);
dev_mode:
  auto_emit_microblocks: true

chain:
  persist: false
  hard_forks:
    "1": 0
    "5": 1
    "6": 2
  genesis_accounts:
    ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E: 10000000000000000000000

So, the contract deployed in Iris and called in Ceres.

from aepp-sdk-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.