Giter Club home page Giter Club logo

antelope's Introduction

NOTICE: This was formerly the @greymass/eosio library distributed on npmjs. Future distributions will be made using the new organization and namespace, and distributed as @wharfkit/antelope again on npmjs.

To update your codebase, remove the @greymass/eosio library and add the @wharfkit/antelope library, then replace all instances of @greymass/eosio with @wharfkit/antelope in all files.

@wharfkit/antelope

JavaScript library for working with Antelope powered blockchains (formerly EOSIO, still compatible with EOSIO).

Avaiable on npm: https://www.npmjs.com/package/@wharfkit/antelope

Install

npm install @wharfkit/antelope

API Documentation

https://wharfkit.github.io/antelope/

Documentation

Documentation beyond the automatically generated API documentation above is currently incomplete. Until full documentation is complete, the tests themselves provide good reference material on how to do nearly everything.

https://github.com/wharfkit/antelope/tree/master/test

More:

Reporting Issues

If you think you've found an issue with this codebase, please submit a pull request with a failing unit test to better help us reproduce and understand the issue you are experiencing.

To do this, fork this repository and create your own branch. In this new branch, use the test scaffolding at the path below to write code that either fails to execute, throws an error, or doesn't return the anticipated response.

./test/bug-report.ts

This specific test can be run within the root project folder either using make:

grep="bug-report" make test

Or running mocha directly from the installed ./node_modules folder:

TS_NODE_PROJECT='./test/tsconfig.json' ./node_modules/.bin/mocha -u tdd -r ts-node/register -r tsconfig-paths/register --extension ts test/*.ts --grep="bug-report"

Once your test is failing and successfully shows the issue occurring, please submit a pull request to this repository. Feel free to include any additional details in the body of the pull request that might help us understand the situation.

NOTE: If you are performing API requests from within unit tests, you will need to prepend MOCK_RECORD=true to the above commands in order instruct the test running to execute and cache the API request. Any subsequent API requests will utilize this cache to prevent the test from continously accessing API endpoints. Prefixing your command with MOCK_RECORD=overwrite is also possible which forces the test to ignore the cache and fetch new data.

Running Tests

Run the unit test suite:

make test

Run the unit test suite with coverage:

make coverage

The report for the current version can also be found at: https://wharfkit.github.io/antelope/coverage/

Run the test suite in a browser:

make browser-test

The browser test suite for the current version of the library is available at: https://wharfkit.github.io/antelope/tests.html

Debugging

Instructions and notes on debugging typescript in your IDE. Explains how to match the Mocha test configuration found in the Makefile.

Notes on setting up IDE Debuggers

antelope's People

Contributors

aaroncox avatar apporc avatar dafuga avatar ericpassmore avatar jnordberg avatar mschoenebeck avatar theblockstalk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

antelope's Issues

"eosio_assert_message assertion failure" during account creation

when I'm trying to create an account using wharfkit/antelope library, I get the following response from the transaction broadcast.

{
  transaction_id: '41e2edec3278acba808ee6d9b761786be3862af336dc17f6732319ec893d2a01',
  processed: {
    id: '41e2edec3278acba808ee6d9b761786be3862af336dc17f6732319ec893d2a01',
    block_num: 351244143,
    block_time: '2024-01-09T15:44:49.000',
    producer_block_id: null,
    receipt: null,
    elapsed: 403,
    net_usage: 165,
    scheduled: false,
    action_traces: [ [Object], [Object] ],
    account_ram_delta: null,
    except: {
      code: 3050003,
      name: 'eosio_assert_message_exception',
      message: 'eosio_assert_message assertion failure',
      stack: [Array]
    },
    error_code: '10000000000000000000'
  }
}

I can't figure out what's the problem. I'm using an account with R1 public/private key.

I can send money transactions successfully, but account creation fails like this.

following shows how I create new account action:

contract.action(
    "newaccount",
    {
      creator: creatorUsername,
      name: newAccountName,
      owner: {
        threshold: 1,
        keys: [
          {
            key: publicKey,
            weight: 1,
          },
        ],
        accounts: [],
        waits: [],
      },
      active: {
        threshold: 1,
        keys: [
          {
            key: publicKey,
            weight: 1,
          },
        ],
        accounts: [],
        waits: [],
      },
    },
    {
      authorization: [
        {
          actor: creatorUsername,
          permission: "owner",
        },
      ],
    },
  );

and the following shows how I create buy ram action

contract.action(
    "buyrambytes",
    {
      payer: payerUsername,
      receiver: receiverUsername,
      bytes: ramBytes,
    },
    {
      authorization: [
        {
          actor: payerUsername,
          permission: "owner",
        },
      ],
    },
  );

the contract here is coming from import { Contract } from '@wharfkit/contract';

Add call for v1/chain/get_producer_schedule

We need to wrap a call around this endpoint:

https://eos.greymass.com/v1/chain/get_producer_schedule

It returns an ordered schedule at the time of the call containing the producer and their signing authority. Should be relatively easy to type and return the response.

Example response:

{
    "active": {
        "version": 2066,
        "producers": [
            {
                "producer_name": "atticlabeosb",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS7PfA3A4UdfMu2wKbuXdbHn8EWAxbMnFoFWui4X2zsr2oPwdQJP",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "aus1genereos",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS6on4KsoQ3cjhXLixNQxB3jwYhmUhNK9rKTABdmBBZWbfNmhTeU",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "big.one",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS8MpYyXwn3DLqk9Y9XTHYcd6wGGijNqJefFoQEwEoXTq1awZ42w",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "binancestake",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS7unwwVJfmKonrT6Gj46LDiNUPpFhpPALpTe2eofmFeoG74bKKn",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "bitfinexeos1",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS4tkw7LgtURT3dvG3kQ4D1sg3aAtPDymmoatpuFkQMc7wzZdKxc",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "blockpooleos",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS61FDJz3GC42GhaPSsmKh7SxuesyZhjm7hBwBKqN52v1HukEqBu",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "bp.defi",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS5BoXgRJwL7JFvKnV64Q3Ha3ux6x2cP8nnhU9NVrRkyrhPC3m5b",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "eosasia11111",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS76gG6ATpqfVf5KrVjh3f4JAa4EKzAwWabTucNQ4Xv2TmVAj9bN",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "eoscannonchn",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS73cTi9V7PNg4ujW5QzoTfRSdhH44MPiUJkUV6m3oGwj7RX7kML",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "eoseouldotio",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS6SSA4gYCSZ3q9NWpxGsYDv5MWjSwKseyq25RRZexwj8EM6YHDa",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "eosflytomars",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS6Agpfp38bTyRjJDmB4Qb1EpQSq7wnEAsALXgXE7KFSzKjokkFD",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "eosinfstones",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS6CSvGzNhNxVYbcnWSuheNcfzjGeGBY9trR4YAJ4Yvakq4oCh6y",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "eosiosg11111",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS7zVBQMhV7dZ5zRQwBgDmmbFCHA6YcmwW6Dq5CePGpqLR1ZsVAc",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "eoslaomaocom",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS8QgURqo875qu3a8vgZ58qBeu2cTehe9zAWRfpdCXAQipicu1Fi",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "eosnationftw",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS8L12yBrtx7mpewHmjwgJeNb2aLaeQdoDgMW82dzDSu17ec2XNL",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "hashfineosio",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS7jSfvStvbKDmGvQdtrQsCyNkWczXfvh6CHmBVmeypJyHsUrMqj",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "ivote4eosusa",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS6KzD4YVbuXV5uBH5d4Ay4sTzuQk88ivmnWfJPLoo6SFrX6iyqj",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "newdex.bp",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS688SnH8tQ7NiyhamiCzWXAGPDLF9S7K8ga79UBHKFgjS1MhqhB",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "okcapitalbp1",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS6NqWZ1i9KSNoeBiby6Nmf1seAbEfhvrDoCbwSi1hV4cuqqnYRP",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "starteosiobp",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS4wZZXm994byKANLuwHD6tV3R3Mu3ktc41aSVXCBaGnXJZJ4pwF",
                                "weight": 1
                            }
                        ]
                    }
                ]
            },
            {
                "producer_name": "whaleex.com",
                "authority": [
                    0,
                    {
                        "threshold": 1,
                        "keys": [
                            {
                                "key": "EOS88EGcFghfQJER1mDaEe4kDJ7MGDoPmXQfA7q2QMTLLqiYP1UQR",
                                "weight": 1
                            }
                        ]
                    }
                ]
            }
        ]
    },
    "pending": null,
    "proposed": null
}

setting api-key header

hi, i will use nownode's eos api, they require 'api-key' on the header, how can i set this globally? when im creating apiClient?

type error when trying to compile my app

node_modules/@greymass/eosio/src/serializer/encoder.ts:97:9 - error TS2322: Type 'ABISerializableConstructor | ABITypeDescriptor' is not assignable to type 'ABISerializableConstructor'.
Type 'ABITypeDescriptor' is missing the following properties from type 'ABISerializableConstructor': abiName, from
type = args.type
~~~~
node_modules/@greymass/eosio/src/serializer/encoder.ts:98:30 - error TS2339: Property 'abiName' does not exist on type 'ABISerializableConstructor | ABITypeDescriptor'.
Property 'abiName' does not exist on type 'ABITypeDescriptor'.
typeName = args.type.abiName
~~~~~~~

i am getting these errors when importing the package with yarn or using yarn link to link it. then building my app

Authority key sorting

To update an accounts permissions nodeos enforces that the keys are sorted, the sorting logic comes from the fc library and has to be re-created for every type involved. Fortunately due to a quirk of how it is implemented for 99% of cases we can get away with sorting the string representations of the types in question.

For now the Authority type will use the string sorting hack. But long-term we should add a compare requirement to all core types and replicate fc's sorting behavior for all of them.

Attaching chat log from Telegram discussing this for posterity

Aaron Cox (jesta) — Greymass, [Jan 27, 2021 11:44:43 (Jan 27, 2021 11:45:13)]:
https://github.com/EOSIO/eos/blob/0d87dff8bee56179aa01472dd00a089b2aa7b9fa/libraries/chain/include/eosio/chain/authority.hpp#L273

By what method are keys sorted here? We are digging through the source, trying to replicate the sorting in the frontend/wallet layer to ensure transactions we generate with multiple keys in an authority are ordered properly - but haven't found the answer yet.

This was a fun one to track down as to why some multikey auth updates were failing 😂

Syed | Bloks.io, [Jan 27, 2021 11:46:59 (Jan 27, 2021 11:47:04)]:
just localeCompare the key or actor in JS

Johan Nordberg, [Jan 27, 2021 11:52:35]:
Are you saying we should convert the keys to the string (PUB_..) representation and sort them alphabetically?

Syed | Bloks.io, [Jan 27, 2021 11:53:39 (Jan 27, 2021 11:53:44)]:
alphanumerically using localeCompare

required_auth.keys     = required_auth.keys.sort((a: { key: any; }, b: { key: any; }) => a.key.localeCompare(b.key))
required_auth.accounts = required_auth.accounts.sort((a: { permission: { actor: any; }; }, b: { permission: { actor: any; }; }) => a.permission.actor.localeCompare(b.permission.actor))
required_auth.waits    = required_auth.waits.sort((a: { wait_sec: any; }, b: { wait_sec: any; }) => a.wait_sec.localeCompare(b.wait_sec))

Johan Nordberg, [Jan 27, 2021 11:54:50]:
Does that work with R1 keys as well?

Syed | Bloks.io, [Jan 27, 2021 11:55:05]:
probably, try it out and let me know

Aarin Hagerty, [Jan 27, 2021 12:05:38 (Jan 27, 2021 12:11:02)]:
That is an interesting coincidence if that actually works. Especially given how arbitrary it is that the variant ordering of the three different types of keys just happens to be consistent with the lexicographic ordering of the ASCII characters of the key type prefixes.

Johan Nordberg, [Jan 27, 2021 12:12:08]:
It seems to be working

Looks like it would work with WA_ keys as well since that's the third variant (and I'm understanding how fc sorts variants correctly)

Someone should put a note in that code saying that the next key prefix has to start with X or they will break everyone 😂

Aarin Hagerty, [Jan 27, 2021 12:16:12 (Jan 27, 2021 12:17:59)]:
Yeah. That’s the coincidence part. First, EOSIO supported K1 and R1 keys and the prefixes were PUB_K1_ and PUB_R1_ respectively. Those prefixes happened to be sorted in the same order as the key types are sorted in the variant. Then later WebAuthn keys were added which had to necessarily be the third entry in the variant for backwards compatibility reasons. Well it really worked out that the obvious prefix for it (PUB_WA_) happened to be sorted last.

Syed | Bloks.io, [Jan 27, 2021 12:19:19 (Jan 27, 2021 12:19:49)]:
Well I found it by tinkering about god knows when 😄 the K, R, W is pure chance for sure

Johan Nordberg, [Jan 27, 2021 12:23:31]:
Awesome, thanks for the help

Aarin Hagerty, [Jan 27, 2021 12:25:16 (Jan 27, 2021 12:38:25)]:
Although I think it still may break down for WebAuthn keys already if the rpId is sufficiently different for otherwise identical keys in the same authority.

For example, I would try with an authority containing two WebAuthn keys with different rpId. The one that has an rpId which is sorted earlier lexicographically should have a longer rpId than the other one. So more concretely, two WebAuthn keys that are exactly identical except for the rpId. One could have an rpId of longer.com and the other can have an rpId of short.com. I believe your sorting method will put them in an order that might be rejected by nodeos.

Johan Nordberg, [Jan 27, 2021 12:52:02]:
Too bad, do you happen to know where in FC one would look to see exactly how they would be sorted? I've gotten as far as the variants numbered 1,2,3 etc and sorted on that and assuming that the key data is just compared byte by byte since it works with the base58 representation

Aarin Hagerty, [Jan 27, 2021 13:32:47 (Jan 27, 2021 13:36:15)]:
EOSIO/eos
An open source smart contract platform . Contribute to EOSIO/eos development by creating an account on GitHub.

Aarin Hagerty, [Jan 27, 2021 13:32:47 (Jan 27, 2021 13:36:15)]:
It’s messy. The representation of the public key people normally see and deal with is the string representation that includes the prefix and base58 encoding of data which consists of the binary serialization of the relevant parts of the public key (without the discriminator determining the type of the public key) appended with checksum data committing to that binary serialization. When nodeos does its validations it is comparing the public key data structures that have been deserialized from the full binary serialization. At the outer layer (the one triggered by this line https://github.com/EOSIO/eos/blob/0d87dff8bee56179aa01472dd00a089b2aa7b9fa/libraries/chain/include/eosio/chain/authority.hpp#L273), it triggers this code: https://github.com/EOSIO/fc/blob/a3694752d2dd2021185955eafc1a504efaabfa79/src/crypto/public_key.cpp#L100-L103.  That then triggers this code (https://github.com/EOSIO/fc/blob/a3694752d2dd2021185955eafc1a504efaabfa79/include/fc/crypto/common.hpp#L168-L170) which sorts all K1 keys before all R1 keys and all R1 keys before WebAuthn keys. To compare two keys of the same type, it delegates that to this line (https://github.com/EOSIO/fc/blob/a3694752d2dd2021185955eafc1a504efaabfa79/include/fc/crypto/common.hpp#L162) which should then call the appropriate template specialization of the apply function depending on the underlying types used for the different types of keys. Actually in all three cases it just gets to this line (https://github.com/EOSIO/fc/blob/a3694752d2dd2021185955eafc1a504efaabfa79/include/fc/crypto/common.hpp#L148) but with type T instantiated to one of three different types. In the case of K1 and R1 keys, the serialize call just returns a fc::array<char,33> which was the only data ultimately stored within the _storage field here (https://github.com/EOSIO/fc/blob/a3694752d2dd2021185955eafc1a504efaabfa79/include/fc/crypto/public_key.hpp#L45) for K1 and R1 keys; this was set during the creation of the public_key object (perhaps from deserialization) to the 33-byte serialized compact representation of an elliptic curve point. There is a less than operator defined on the fc::array types which just compares them lexicographically. In the case of WebAuthn keys, the serialize call just returns the fc::crypto::webauthn::public_key type (https://github.com/EOSIO/fc/blob/a3694752d2dd2021185955eafc1a504efaabfa79/include/fc/crypto/elliptic_webauthn.hpp#L21) which has a less than operator defined on it: https://github.com/EOSIO/fc/blob/a3694752d2dd2021185955eafc1a504efaabfa79/include/fc/crypto/elliptic_webauthn.hpp#L44. The public_key_data field is the same as the 33-byte data from R1 keys. The user_verification_type field is a single byte representing the user presence flag of the WebAuthn key. And the rpid key is the rpId of the WebAuthn key (https://www.w3.org/TR/webauthn-2/#relying-party-identifier). All of these fields are extracted from the raw binary during deserialization (https://github.com/EOSIO/fc/blob/a3694752d2dd2021185955eafc1a504efaabfa79/include/fc/crypto/elliptic_webauthn.hpp#L55-L64). Note that when I am talking about the raw binary form I am not talking about Base58 encoding. The raw binary form is at the beginning of the binary string resulting from parsing the Base58 encoding after the prefix within the string representation of the public key. That resulting binary string also has a 4 byte checksum at the end which commits to the raw binary form as well as the prefix type. You can find the code for that here: https://github.com/EOSIO/fc/blob/a3694752d2dd2021185955eafc1a504efaabfa79/include/fc/crypto/common.hpp#L10-L86.

Johan Nordberg, [Jan 27, 2021 13:46:49]:
Wow thanks! So If I understand this correctly I should be able to (after base58check decoding the key data): compare(data[0:33]) && compare(data[33:34]) && compare(data[34:])

Aarin Hagerty, [Jan 27, 2021 13:48:27]:
I don’t think the && is the correct way to express the tie breaking but you have the general idea right with the exception that comparing the last field is a bit more complicated.

The serialization of an std::string to binary form should first pack the length as a variable-length integer and then the bytes of the string.

But the strings are compared lexicographically. Hence longer.com should come before short.com but in the serialization the first byte of longer.com would be 10 (its length) while the first byte of short.com would be 9 (again its length). That means just comparing the raw bytes would consider short.com to come before longer.com.

Johan Nordberg, [Jan 27, 2021 13:52:35]:
Ok got it, so that's why you can't compare the base58 encoded string version of the key

Aarin Hagerty, [Jan 27, 2021 13:53:03]:
Right. It was so very close, but I do believe that example I gave above would break it (haven’t verified though).

secp256k1 may not be suitable for EDCH encryption: they are susceptible to Twist Attacks

secp256k1 keys may not be suitable for EDCH

I found out about this issue when looking into using a secp256k1 key using the well supported did-jwt library, where I found this note: https://github.com/decentralized-identity/veramo/blob/0c22cc6a79e974214500e4440b0ea2977012377d/packages/utils/src/did-utils.ts#L269

I then followed up and found secp256k1 keys are not supported due to Twist attacks. See here

This issue is prevalent during the EDCH code found in https://github.com/wharfkit/antelope/blob/master/src/crypto/shared-secret.ts

Want to deserialize SHIP data, cannot import ABI

I've got a copy of this JSON locally:
https://github.com/AntelopeIO/leap/blob/main/libraries/state_history/abi.cpp

I want to create an ABI object in order to deserialize the state history data, but this JSON doesn't have actions and ricardian clauses:

error TS2739: Type '{ version: string; structs: ({ name: string; fields: { name: string; type: string; }[]; base?: undefined; } | { name: string; base: string; fields: { name: string; type: string; }[]; })[]; types: { new_type_name: string; type: string; }[]; variants: { ...; }[]; tables: { ...; }[]; }' is missing the following properties from type 'Def': actions, ricardian_clauses

Add new leap 4.0 API endpoints

Not sure what they all are yet, but do know a v1/chain/send_read_only_transaction will exist.

Need to get release notes and see what changed, then add them in.

get_account API does not return linked_actions

Steps to reproduce

const account = api.v1.chain.get_account()
const permission = account.getPermission("active")

Expected

  • result has a property for the linked_actions field returned in the HTTP response

Actual

  • linked_actions property not found

image

Unexpectedly encountered null for non-optional in get_account response

In a developer environment, I have deployed the eosio.bios account but not a token.

When I call api.v1.chain.get_account("account_name") I receive an account response such as the one below

{
   "account_name": "xprq3ryq2ewx",
   "head_block_num": 153,
   "head_block_time": "2022-08-23T19:11:48.500",
   "privileged": false,
   "last_code_update": "1970-01-01T00:00:00.000",
   "created": "2022-08-23T19:10:57.000",
   "ram_quota": -1,
   "net_weight": -1,
   "cpu_weight": -1,
   "net_limit": {
      "used": -1,
      "available": -1,
      "max": -1
   },
   "cpu_limit": {
      "used": -1,
      "available": -1,
      "max": -1
   },
   "ram_usage": 3898,
   "permissions": [...],
   "total_resources": null,
   "self_delegated_bandwidth": null,
   "refund_request": null,
   "voter_info": null,
   "rex_info": null,
   "subjective_cpu_bill_limit": {
      "used": 0,
      "available": 0,
      "max": 0
   }
}

as you can see, several items have a null value, which when processed are causing the following error

Unexpectedly encountered null for non-optional

      at decodeObject (node_modules/@greymass/eosio/src/serializer/decoder.ts:244:6)

I am using @greymass/eosio-core 0.6.2. It seems to me that the library should work for all chains, even if not fully initialized with a resource token. Hope this helps.

Document IDE Debugging Setup

Ok for me to add a new directory and file docs/IDE_Debug.md and link from README?

I'm not used to using make files for building TS/JS packages. Took some research to get the options right for Webstorm. Want to write down my notes for my future self and others. If this is ok, assign the issue to me and I'll build the pull request.

Missing uncompressed public keys

With the new k1_recover intrinsics launching, I need a way to get uncompressed keys from @greymass/eosio

Seems recover and getPublic both compress the keys

Plus there is no uncompressed publickey type in eosio-core

Serializer.decode error: Unknown type

Code to reproduce the failure:

https://github.com/EOSChronicleProject/chronos-client-npm/blob/af4762f00d23cdf108e43cb8bd430b7f3c2f2d5e/tmp/wharf_abi_decode_failure.js

Error message:

# node tmp/wharf_abi_decode_failure.js 
node:internal/process/esm_loader:97
    internalBinding('errors').triggerUncaughtException(
                              ^

DecodingError: Unknown type
    at decodeInner (/opt/src/chronos-client-npm/node_modules/@greymass/eosio/lib/eosio-core.js:1246:23)
    at decodeBinary (/opt/src/chronos-client-npm/node_modules/@greymass/eosio/lib/eosio-core.js:1192:16)
    at Object.abiDecode [as decode] (/opt/src/chronos-client-npm/node_modules/@greymass/eosio/lib/eosio-core.js:1144:20)
    at file:///opt/src/chronos-client-npm/tmp/wharf_abi_decode_failure.js:9:25
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25) {
  ctx: {
    types: {
      bool: {
        abiName: 'bool',
        abiDefault: [Function: abiDefault],
        fromABI: [Function: fromABI],
        from: [Function: from],
        toABI: [Function: toABI]
      },
      string: {
        abiName: 'string',
        abiDefault: [Function: abiDefault],
        fromABI: [Function: fromABI],
        from: [Function: from],
        toABI: [Function: toABI]
      },
      asset: [class Asset] {
        abiName: 'asset',
        Symbol: [class Symbol] {
          abiName: 'symbol',
          symbolNamePattern: /^[A-Z]{0,7}$/,
          maxPrecision: 18
        },
        SymbolCode: [class SymbolCode] { abiName: 'symbol_code' }
      },
      symbol: [class Symbol] {
        abiName: 'symbol',
        symbolNamePattern: /^[A-Z]{0,7}$/,
        maxPrecision: 18
      },
      symbol_code: [class SymbolCode] { abiName: 'symbol_code' },
      block_timestamp_type: [class BlockTimestamp extends TimePointBase] {
        abiName: 'block_timestamp_type'
      },
      bytes: [class Bytes] { abiName: 'bytes' },
      checksum160: [class Checksum160 extends Checksum] {
        abiName: 'checksum160',
        byteSize: 20
      },
      checksum256: [class Checksum256 extends Checksum] {
        abiName: 'checksum256',
        byteSize: 32
      },
      checksum512: [class Checksum512 extends Checksum] {
        abiName: 'checksum512',
        byteSize: 64
      },
      extended_asset: [class ExtendedAsset] { abiName: 'extended_asset' },
      float128: [class Float128] { abiName: 'float128', byteWidth: 16 },
      float32: [class Float32 extends Float] { abiName: 'float32', byteWidth: 4 },
      float64: [class Float64 extends Float] { abiName: 'float64', byteWidth: 8 },
      int128: [class Int128 extends Int] {
        abiName: 'int128',
        byteWidth: 16,
        isSigned: true
      },
      int16: [class Int16 extends Int] {
        abiName: 'int16',
        byteWidth: 2,
        isSigned: true
      },
      int32: [class Int32 extends Int] {
        abiName: 'int32',
        byteWidth: 4,
        isSigned: true
      },
      int64: [class Int64 extends Int] {
        abiName: 'int64',
        byteWidth: 8,
        isSigned: true
      },
      int8: [class Int8 extends Int] {
        abiName: 'int8',
        byteWidth: 1,
        isSigned: true
      },
      name: [class Name] { abiName: 'name', pattern: /^[a-z1-5.]{0,13}$/ },
      public_key: [class PublicKey] { abiName: 'public_key' },
      signature: [class Signature] { abiName: 'signature' },
      time_point: [class TimePoint extends TimePointBase] { abiName: 'time_point' },
      time_point_sec: [class TimePointSec extends TimePointBase] {
        abiName: 'time_point_sec'
      },
      uint128: [class UInt128 extends Int] {
        abiName: 'uint128',
        byteWidth: 16,
        isSigned: false
      },
      uint16: [class UInt16 extends Int] {
        abiName: 'uint16',
        byteWidth: 2,
        isSigned: false
      },
      uint32: [class UInt32 extends Int] {
        abiName: 'uint32',
        byteWidth: 4,
        isSigned: false
      },
      uint64: [class UInt64 extends Int] {
        abiName: 'uint64',
        byteWidth: 8,
        isSigned: false
      },
      uint8: [class UInt8 extends Int] {
        abiName: 'uint8',
        byteWidth: 1,
        isSigned: false
      },
      varint32: [class VarInt extends Int] {
        abiName: 'varint32',
        byteWidth: 32,
        isSigned: true
      },
      varuint32: [class VarUInt extends Int] {
        abiName: 'varuint32',
        byteWidth: 32,
        isSigned: false
      }
    },
    strictExtensions: false,
    codingPath: [
      {
        field: 'root',
        type: ResolvedType {
          isExtension: false,
          isOptional: false,
          isArray: false,
          id: 1,
          name: 'claimprize'
        }
      }
    ]
  },
  underlyingError: Error: Unknown type
      at decodeInner (/opt/src/chronos-client-npm/node_modules/@greymass/eosio/lib/eosio-core.js:1246:23)
      at decodeBinary (/opt/src/chronos-client-npm/node_modules/@greymass/eosio/lib/eosio-core.js:1192:16)
      at Object.abiDecode [as decode] (/opt/src/chronos-client-npm/node_modules/@greymass/eosio/lib/eosio-core.js:1144:20)
      at file:///opt/src/chronos-client-npm/tmp/wharf_abi_decode_failure.js:9:25
      at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
}

Node.js v18.13.0

Transaction ID on WAX: bde4e9ad905af3c9ee322473eea25bb7d7529b272c7c884d4dfd9ca00565c213

Helper to return the serialized transaction from a transaction object

A nice convenience method would be to add a .serialized get helper on to the Transaction structs. Currently we need to import the Serializer and serialize it ourselves using:

const serializedTransaction = Serializer.encode({ object: transaction }).array;

I'm sure there are more transaction transformation helpers that could also be useful on top of that. It's an area we might want to explore.

Found undefined for non-optional type: name

Code seems to be working in the browser, however executing it locally with ts-node index.ts throws the following error:

/Users/denis/Github/typescript-i1q86h/node_modules/@greymass/eosio/src/serializer/encoder.ts:182
            throw new Error(`Found ${value} for non-optional type: ${type.typeName}`)
                  ^
EncodingError: Found undefined for non-optional type: name

Code Example

https://stackblitz.com/edit/typescript-i1q86h

Code snippet

import { Struct, Name, Asset, Action, NameType, AssetType } from '@greymass/eosio';

@Struct.type('transfer')
class Transfer extends Struct {
  @Struct.field('name') from!: Name;
  @Struct.field('name') to!: Name;
  @Struct.field('asset') quantity!: Asset;
  @Struct.field('string') memo!: string;
}

export function transferAction( from: NameType, to: NameType, quantity: AssetType, memo: string ): Action {
  return Action.from({
    authorization: [ { actor: from, permission: "active" } ],
    account: "eosio.token",
    name: 'transfer',
    data: Transfer.from({
      from,
      to,
      quantity,
      memo,
    }),
  })
}

const action = transferAction("myaccount", "toaccount", "1.0000 EOS", "foo");
console.log(action.toJSON())

How to supppress variant types in Serializer.decode()?

Code in question: https://github.com/EOSChronicleProject/chronos-client-npm/blob/abb109e10094c7ae4d5062753b2cf767793c3d71/src/chronos-client.ts#L39

I'm loading the SHIP ABI definition into an ABI object, and calling Serializer.decode()' to convert a binary representation of transaction_trace` into JSON.

For every variant, I'm getting a pair [name, value], instead of just value:

[
  "transaction_trace_v0",
  {
    "id": "fc885861953788adcd2515099d7210196a07d7f0656c0f5048203833b9a0578e",
    "status": 0,
    "cpu_usage_us": 273,
    "net_usage_words": 0,
    "elapsed": 101,
    "net_usage": 0,
    "scheduled": true,
    "action_traces": [
      [
        "action_trace_v0",
        {
          "action_ordinal": 1,
          "creator_action_ordinal": 0,

It seems like this line is doing that: https://github.com/greymass/eosio-core/blob/f0d1c8811cfec24f43e25431ba3700f76f35634c/src/serializer/decoder.ts#L213

How can I instruct the decoder that I only need the value, and not the type name?

Bug report

Summary:

Steps to Reproduce:

Expected Results:

Actual Results:

Environment:

Additional Information:

Attempted Diagnoses:

Include `Asset.SymbolCode.pattern` as static value

Currently, the Regex patterns use *.pattern as value

import { Name } from "@wharfkit/antelope";

Name.pattern // => /^[a-z1-5.]{0,13}$/

Propose

One would assume that the following would exists:

import { Asset } from "@wharfkit/antelope";

Asset.SymbolCode.pattern // => /^[A-Z]{0,7}$/

I know the Regex pattern exists in Asset.SymbolCode.symbolNamePattern, but it's not intuitive at first

Adding transaction data to the TransactionReceipt

I'd like to add in the trx field to the TransactionReceipt class, but with it returning different data types conditionally based on the status, I'm not entirely sure how to do that.

The code in question is:

https://github.com/greymass/eosio-core/blob/9f1d6676bc4957b60205ca0d65eac40697aafe74/src/chain/transaction.ts#L203-L208

You can see an example of the different types of data in the trx field in our tests here:

https://github.com/greymass/eosio-core/blob/9f1d6676bc4957b60205ca0d65eac40697aafe74/test/data/f3ada964795e1371af75486638632e6b04f37035.json#L11-L27

It looks to be either a Checksum256 if the transaction is expired, or a PackedTransaction if the transaction is executed.

get actions instead of traces

i want to get only the actions created by the creator of the transaction but history api returns whole transaction to me,

im using the following code snippet to get the transaction

const transaction = await this.indexerRequest(
      EOS_INDEXER_API.V2.GET_TRANSACTION,
      {
        params: {
          id: transactionHash,
        },
        method: GET_METHOD,
      },
    );

example transaction

for example in here, i want to only filter the following actions, not traces, which are
image

how to filter correctly? i tried to use creator_action_ordinal but thats not what i was looking for

thanks, Dante

Add antelope IBC data types

It would be cool if antelope IBC data types will be added as typescript types for proofs and related interfaces with bridge.

wrong net usage

example transaction

looking in this transaction, explorer shows net usage as 136 bytes, but when i fetch this data using the indexer, i always get 1/8th of the net usage, which is 17 in this case.

I wonder which is correct, is it 17 bytes and 136 bits, or 136 bytes and 17 x something?

thanks, Dante

Add deep copy method to types

We frequently find the need to clone a core type as not to mutate it for the caller. Add a .clone() protocol requirement and implementation to all core types.

how to check if an account is inactive

when i was checking the internet i saw something like this: 'You can’t delete account but you could undelegate all staked EOS and effectively leave that account inactive.'

how can i check if an account is inactive? is this means if an account doesn't have any eos, its not active? or is there any other check i should do?

Fields missing from voter_info in get_account API response on WAX

Summary:
The get_account API response on WAX differs slightly from the base response of Antelope.
These include the following fields:

unpaid_voteshare  
unpaid_voteshare_last_updated  
unpaid_voteshare_change_rate  
last_claim_time

Steps to Reproduce:

  1. Call .v1.chain.get_account() against a WAX node.
  2. Get AccountObject response and inspect voter_info.
  3. voter_info object does not include all expected fields.

Expected Results:

{
    "owner": "includenull",
    "proxy": "top21.oig",
    "producers": [],
    "staked": "125699191765",
    "unpaid_voteshare": "1018386344149210818270928864637142440083456.00000000000000000",
    "unpaid_voteshare_last_updated": "2023-08-13T10:01:30.000",
    "unpaid_voteshare_change_rate": "4243396489486260233891840133040504307712.00000000000000000",
    "last_claim_time": "2023-08-13T09:57:03.000",
    "last_vote_weight": "4243396489486260233891840133040504307712.00000000000000000",
    "proxied_vote_weight": "0.00000000000000000",
    "is_proxy": 0,
    "flags1": 0,
    "reserved2": 0,
    "reserved3": "0 "
}

Actual Results:

{
  "owner": "includenull",
  "proxy": "top21.oig",
  "producers": [],
  "staked": "125699191765",
  "last_vote_weight": "4.24339648948626e+39",
  "proxied_vote_weight": "0",
  "is_proxy": 0,
  "flags1": 0,
  "reserved2": 0,
  "reserved3": "0 "
}

Additional Information:
I consider this a bug because the available data is not passed through to the object.
These missing fields are required to calculate voter rewards.

I am unaware of any other way to calculate voter rewards without this data, which surprises me that these are missing from the base Antelope response.

Using `esnext` as target breaks some decoding

Just stumbled into this in a nodejs project, when setting "target": "esnext" in the tsconfig.json, it prevents some structs from rendering properly.

Sample code:

const sample =
    '80b1915e5d268dca000000000090b1ca01000000403290b1ca00000000a8ed3232e2e1006500000000000000000000017055cb2a5fd5b2ca000000572d3ccdcd01000000403290b1ca00000000a8ed32322a000000403290b1ca00000092019ca65e010000000000000004555344540000000954657374206d73696700'

@Struct.type('propose')
class Propose extends Struct {
    @Struct.field(Name) proposer!: Name
    @Struct.field(Name) proposal_name!: Name
    @Struct.field(PermissionLevel, {array: true}) requested!: PermissionLevel[]
    @Struct.field(Transaction) trx!: Transaction
}

const broken = Serializer.decode({
    data: sample,
    type: Propose,
})

console.log(broken)

This causes the output to be:

Propose {
  proposer: undefined,
  proposal_name: undefined,
  requested: undefined,
  trx: undefined
}

However when I switch to using "target": "es2020", the same code above outputs:

Propose {
  proposer: Name { value: UInt64 { value: [BN] } },
  proposal_name: Name { value: UInt64 { value: [BN] } },
  requested: [ PermissionLevel { actor: [Name], permission: [Name] } ],
  trx: Transaction {
    expiration: TimePointSec { value: [UInt32] },
    ref_block_num: UInt16 { value: [BN] },
    ref_block_prefix: UInt32 { value: [BN] },
    max_net_usage_words: VarUInt { value: [BN] },
    max_cpu_usage_ms: UInt8 { value: [BN] },
    delay_sec: VarUInt { value: [BN] },
    context_free_actions: [],
    actions: [ [Action] ],
    transaction_extensions: []
  }
}

Not sure what in esnext breaks this, and not sure if we need to fix - but recording here for sake of jotting it down somewhere.

Add missing fields to `GetTransactionStatusResponse`

The API response for this call has changed, and the fields need to be matched up again with the new response.

export class GetTransactionStatusResponse extends Struct {
@Struct.field('string') declare state: string
@Struct.field('uint32') declare head_number: UInt32
@Struct.field(BlockId) declare head_id: BlockId
@Struct.field('time_point') declare head_timestamp: TimePoint
@Struct.field('uint32') declare irreversible_number: UInt32
@Struct.field(BlockId) declare irreversible_id: BlockId
@Struct.field('time_point') declare irreversible_timestamp: TimePoint
@Struct.field(BlockId) declare earliest_tracked_block_id: BlockId
@Struct.field('uint32') declare earliest_tracked_block_number: UInt32
}

telegram-cloud-photo-size-1-5186297521478151471-y

Adding `action_results` to the `ABI` struct

This field (and potentially others) are missing from the ABI struct definition, causing them to not be serialized and included in transaction data.

This field needs to be added in and we should determine if other fields are missing - adding them as well.

Conversation starts here on Telegram: https://t.me/wharfkit/1822

how to get latest ram price?

how can i get latest Ram price on the chain using antelope api?

bonus: also is there a way to learn EOS PowerUp Model prices for cpu and net using antelope api?

thanks, dante

Missing error details on API error

The error created from an error response from API calls is missing and not printing extra information in the json.error.details object that would be useful for developers to see. Only the json.error.name and json.error.what is printed.

Error response from v1.chainpush_transaction:

{
      headers: {
        'access-control-allow-headers': '*',
        'access-control-allow-origin': '*',
        connection: 'close',
        'content-length': '531',
        'content-type': 'application/json',
        server: 'WebSocket++/0.7.0'
      },
      status: 500,
      json: {
        code: 500,
        message: 'Internal Service Error',
        error: {
          code: 3090003,
          name: 'unsatisfied_authorization',
          what: 'Provided keys, permissions, and delays do not satisfy declared authorizations',
          details: [
            {
              message: "transaction declares authority '${auth}', but does not have signatures for it under a provided delay of 0 ms, provided permissions ${provided_permissions}, provided keys ${provided_keys}, and a delay max limit of 3888000000 ms",
              file: 'authorization_manager.cpp',
              line_number: 532,
              method: 'check_authorization'
            }
          ]
        }
      },
      text: '{"code":500,"message":"Internal Service Error","error":{"code":3090003,"name":"unsatisfied_authorization","what":"Provided keys, permissions, and delays do not satisfy declared authorizations","details":[{"message":"transaction declares authority \'${auth}\', but does not have signatures for it under a provided delay of 0 ms, provided permissions ${provided_permissions}, provided keys ${provided_keys}, and a delay max limit of 3888000000 ms","file":"authorization_manager.cpp","line_number":532,"method":"check_authorization"}]}}'
    }

Add PUB_WA support

Is your feature request related to a problem? Please describe.
Add support of PUB_WA key to PublicKey class, pls check that signature and the rest of the function will work for this type of key.

Describe the solution you'd like
PUB_WA key type is supported, seamlessly.

Describe alternatives you've considered
N/A

Additional context
N/A

Serializer.decode failure

while testing my history database, Wharf failed to decode an action in WAX transaction ae2639af9b5b3bdf6359ec860a9287f633aad09b50805811bbee02f7f3407b24:

         "act": {
            "account": "deepmineappg",
            "name": "updinvavfrom",
            "authorization": [
              {
                "actor": "deepmineappg",
                "permission": "dmgactions"
              }
            ],
            "data": "30700506000100004d884164"
          },

Hyperion output for the same transaction:

     "act": {
        "account": "deepmineappg",
        "name": "updinvavfrom",
        "authorization": [
          {
            "actor": "deepmineappg",
            "permission": "dmgactions"
          }
        ],
        "data": {
          "asset_id": "1099612647472",
          "available_from": 1682016333
        }

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.