{"id":28172982,"url":"https://github.com/archethic-foundation/libgo","last_synced_at":"2026-02-18T10:03:10.402Z","repository":{"id":161054268,"uuid":"414142396","full_name":"archethic-foundation/libgo","owner":"archethic-foundation","description":"Archethic Golang SDK","archived":false,"fork":false,"pushed_at":"2025-03-26T16:13:46.000Z","size":120,"stargazers_count":0,"open_issues_count":5,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-10-14T19:52:55.917Z","etag":null,"topics":["archethic","blockchain","cryptography","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/archethic-foundation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-10-06T09:08:42.000Z","updated_at":"2025-03-26T16:13:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"80647ee8-96eb-42d2-80a4-22b0f145cba4","html_url":"https://github.com/archethic-foundation/libgo","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/archethic-foundation/libgo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archethic-foundation%2Flibgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archethic-foundation%2Flibgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archethic-foundation%2Flibgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archethic-foundation%2Flibgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/archethic-foundation","download_url":"https://codeload.github.com/archethic-foundation/libgo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archethic-foundation%2Flibgo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29575343,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T08:38:15.585Z","status":"ssl_error","status_checked_at":"2026-02-18T08:38:14.917Z","response_time":162,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["archethic","blockchain","cryptography","golang"],"created_at":"2025-05-15T20:11:32.632Z","updated_at":"2026-02-18T10:03:10.379Z","avatar_url":"https://github.com/archethic-foundation.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Archethic's golang library\n\nOfficial Archethic golang library\n\n\n## Installing\n\n```bash\ngo get github.com/archethic-foundation/libgo\n```\n\n## Usage\n\nThis library aims to provide an easy way to create Archethic transaction and to send them over the network.\n\n## API\n\n  \u003cdetails\u003e\n  \u003csummary\u003eCryptographic functions\u003c/summary\u003e\n  \u003cbr/\u003e\n\n  #### deriveKeyPair(seed, index, curve)\n  It creates a new keypair into hexadecimal format\n\n  - `seed` is a slice of bytes representing the transaction chain seed to be able to derive and generate the keys\n  - `index` is the number of transactions in the chain, to generate the actual and the next public key (see below the cryptography section)\n  - `curve` is the elliptic curve to use for the key generation (can be \"ED25519\", \"P256\", \"SECP256K1\")\n\n```go\nimport (\n    ...\n\tarchethic \"github.com/archethic-foundation/libgo\"\n)\n\n    publicKey, privateKey := archethic.DeriveKeypair([]byte(\"seed\"), uint32(0), archethic.ED25519)\n    publicKeyHex := hex.EncodeToString(publicKey)\n    // publicKeyHex: 000161d6cd8da68207bd01198909c139c130a3df3a8bd20f4bacb123c46354ccd52c\n\n```\n\n  #### deriveAddress(seed, index, curve, hashAlgo)\n  It creates a transaction address by extract the public key from the key derivation and hash it into a hexadecimal format\n\n   - `seed` is a slice of bytes representing the transaction chain seed to be able to derive and generate the keys\n   - `index` is the number of transactions in the chain, to generate the actual and the next public key (see below the cryptography section)\n   - `curve` is the elliptic curve to use for the key generation (can be \"ED25519\", \"P256\", \"SECP256K1\")\n   - `hashAlgo` is the hash algorithm to create the address (can be \"SHA256\", \"SHA512\", \"SHA3_256\", \"SHA3_512\", \"BLAKE2B\")\n\n   ```go\n   import(\n    ...\n    archethic \"github.com/archethic-foundation/libgo\"\n    )\n   address := archethic.DeriveAddress([]byte(\"mysuperseed\"), uint32(0), archethic.ED25519, archethic.SHA256)\n   // Address: 0000b0c17f85ca19e3db670992e79adb94fb560bd750fda06d45bc0a42912c89d31e\n   ```\n\n  #### ecEncrypt(data, publicKey)\n  Perform an ECIES encryption using a public key and a data\n\n  - `data` Data to encrypt\n  - `publicKey` Public key to derive a shared secret and for whom the content must be encrypted\n\n  ```go\n  import (\n    ...\n\tarchethic \"github.com/archethic-foundation/libgo\"\n    )\n\n  \ttextToEncrypt := []byte(\"hello\")\n\tpublicKey, _ := archethic.DeriveKeypair([]byte(\"seed\"), 0, archethic.P256)\n\tcipherText := archethic.EcEncrypt(textToEncrypt, publicKey)\n  ```\n\n  #### aesEncrypt(data, publicKey)\n  Perform an AES encryption using a key and a data\n\n  - `data` Data to encrypt\n  - `key` Symmetric key\n\n  ```go\n    import (\n    ...\n\tarchethic \"github.com/archethic-foundation/libgo\"\n    )\n\n    key := make([]byte, 32)\n\trand.Read(key)\n\tdataToEncrypt := []byte(\"hello\")\n\tencryptedData := archethic.AesEncrypt(dataToEncrypt, key)\n  ```\n\n  \u003c/details\u003e\n   \u003cbr/\u003e\n   \u003cdetails\u003e\n   \u003csummary\u003eTransaction building\u003c/summary\u003e\n   \u003cbr/\u003e\n\n  `tx := archethic.TransactionBuilder{}` creates a new instance of the transaction\n\n  The transaction instance contains the following methods:\n\n  #### SetType(type)\n  Sets the type of the transaction (could be `TransferType`, `ContractType`, `DataType`, `TokenType`, `HostingType`, `CodeProposalType`, `CodeApprovalType`)\n\n  #### SetCode(code)\n  Adds the code in the `data.code` section of the transaction\n  `code` is a string defining the smart contract\n\n  #### SetContent(content)\n  Adds the content in the `data.content` section of the transaction\n  `content` is a string defining the smart contract\n\n  #### AddOwnership(secret, authorizedKeys)\n   Adds an ownership in the `data.ownerships` section of the transaction with a secret and its related authorized public keys to be able to decrypt it.\n   This aims to prove the ownership or the delegatation of some secret to a given list of public keys.\n  `secret` is the slice of bytes representing the encrypted secret\n  `authorizedKeys` is a list of object represented by\n  - `publicKey` is the slice of bytes representing the public key\n  - `encryptedSecretKey` is the slice of bytes representing the secret key encrypted with the public key (see `ecEncrypt`)\n\n  #### AddUCOTransfer(to, amount)\n  Adds a UCO transfer to the `data.ledger.uco.transfers` section of the transaction\n  - `to` is the slice of bytes representing the transaction address (recipient) to receive the funds\n  - `amount` is the number of uco to send, the `ToUint64(number float64, decimals int) uint64` function can help build the proper amount, for example `ToUint64(10.03, 8)`\n\n  #### AddTokenTransfer(to, tokenAddress, amount, tokenId)\n  Adds a token transfer to the `data.ledger.token.transfers` section of the transaction\n  - `to` is the slice of bytes representing the transaction address (recipient) to receive the funds\n  - `tokenAddress` is the slice of bytes representing the token address to spend\n  - `amount` is the number of uco to send, the `ToUint64(number float64, decimals int) uint64` function can help build the proper amount, for example `ToUint64(10.03, 8)`\n  - `tokenId` is the ID of the token to use\n\n  #### AddRecipient(to)\n  Adds a recipient to call the smart contract's \"transaction\" action.\n  - `to` is the contract's address in hexadecimal\n\n  #### AddRecipientWithNamedAction(to, action, args)\n  Adds a recipient to call a specific smart contract's action.\n  - `to` is the contract's address in hexadecimal\n  - `action` is the name of the action\n  - `args` is the list of arguments of the action\n\n  #### Build(seed, index, curve, hashAlgo)\n  Generates `address`, `timestamp`, `previousPublicKey`, `previousSignature` of the transaction and\n  serialize it using a custom binary protocol.\n\n  - `seed` is the slice of bytes representing the transaction chain seed to be able to derive and generate the keys\n  - `index` is the number of transactions in the chain, to generate the actual and the next public key (see below the cryptography section)\n  - `curve` is the elliptic curve to use for the key generation (can be \"ED25519\", \"P256\", \"SECP256K1\")\n  - `hashAlgo` is the hash algorithm to use to generate the address (can be \"SHA256\", \"SHA512\", \"SHA3_256\", \"SHA3_512\", \"BLAKE2B\")\n\n  ```go\n\n  import(\n    ...\n    archethic \"github.com/archethic-foundation/libgo\"\n    )\n    tx := archethic.TransactionBuilder{}\n\ttx.SetType(archethic.TransferType)\n\tucoAddress, _ := hex.DecodeString(\"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\")\n\n\ttx.AddUcoTransfer(\n\t\tucoAddress,\n\t\tarchethic.ToUint64(0.420, 8),\n\t)\n\ttx.Build([]byte(\"mysuperpassphraseorseed\"), 0, archethic.ED25519, archethic.SHA256)\n\n  ```\n\n  #### OriginSign(privateKey)\n  Sign the transaction with an origin device private key\n\n   - `privateKey` is the slice of bytes representing the private key to generate the origin signature to able to perform the ProofOfWork and authorize the transaction\n\n  ```go\n    import(\n    ...\n    archethic \"github.com/archethic-foundation/libgo\"\n    )\n\n    originPublicKey, originPrivateKey := archethic.DeriveKeypair([]byte(\"origin_seed\"), 0, archethic.P256)\n\n\ttx := archethic.TransactionBuilder{}\n\ttx.SetType(archethic.TransferType)\n\n\ttx.Build([]byte(\"seed\"), 0, archethic.P256, archethic.SHA256)\n\ttx.OriginSign(originPrivateKey)\n\tlog.Println(tx.Version)\n\n\t// test, err := archethic.Verify(tx.OriginSignature, tx.OriginSignaturePayload(), originPublicKey)\n  ```\n\n  #### ToJSON()\n  Export the transaction generated into JSON\n\n   ```go\n   import(\n    ...\n    archethic \"github.com/archethic-foundation/libgo\"\n    )\n\n    tx := archethic.TransactionBuilder{}\n\ttx.SetType(archethic.TransferType)\n\tucoAddress, _ := hex.DecodeString(\"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\")\n\n\ttx.AddUcoTransfer(\n\t\tucoAddress,\n\t\tarchethic.ToUint64(0.420, 8),\n\t)\n\ttx.Build([]byte(\"mysuperpassphraseorseed\"), 0, archethic.ED25519, archethic.SHA256)\n    json, _ := tx.ToJSON()\n  ```\n\n  \u003c/details\u003e\n   \u003cbr/\u003e\n   \u003cdetails\u003e\n   \u003csummary\u003eRemote Endpoint calls\u003c/summary\u003e\n   \u003cbr/\u003e\n\n  #### GetOriginKey()\n  Return the hardcoded origin private key for software, this is used for signing transaction (see OriginSign).\n\n  #### AddOriginKey(originPublicKey, certificate, endpoint)\n  Query a node to add a new origin public to be authorized to sign transaction with the corresponding private key (see OriginSign).\n\n  - `originPublicKey` is the public key to be added.\n  - `certificate` is the certificate that prove the public key is allowed to be added.\n\n  ```golang\n    client := archethic.NewAPIClient(\"http://localhost:4000\")\n\n    client.AddOriginKey(\"01103109\", \"mycertificate\")\n  ```\n\n  #### GetLastTransactionIndex(address)\n  Query a node to find the length of the chain to retrieve the transaction index\n\n  - `addresses` Transaction address (in hexadecimal)\n\n  ```golang\n    client := archethic.NewAPIClient(\"http://localhost:4000\")\n    client.GetLastTransactionIndex(\"0000872D96130A2963F1195D1F85FC316AE966644F2E3EE45469C2A257F49C4631C2\")\n  ```\n\n  #### GetStorageNoncePublicKey()\n  Query a node to find the public key of the shared storage node key\n\n   ```golang\n  \tclient := archethic.NewAPIClient(\"https://testnet.archethic.net/api\")\n\tclient.GetStorageNoncePublicKey()\n    // 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F\n  ```\n\n  #### GetTransactionFee(tx)\n  Query a node to fetch the tx fee for a given transaction\n\n  - `tx` Generated transaction\n\n  ```golang\n\n    client := archethic.NewAPIClient(\"http://localhost:4000\")\n\n\ttx := archethic.TransactionBuilder{}\n\ttx.SetType(archethic.TransferType)\n\tucoAddress, _ := hex.DecodeString(\"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\")\n\n\ttx.AddUcoTransfer(\n\t\tucoAddress,\n\t\tarchethic.ToUint64(0.420, 8),\n\t)\n\ttx.Build([]byte(\"mysuperpassphraseorseed\"), 0, archethic.ED25519, archethic.SHA256)\n\tclient.GetTransactionFee(\u0026tx)\n  ```\n\n  #### GetTransactionOwnerships(addresses)\n  Query a node to find the ownerships (secrets and authorized keys) to given transactions addresses\n\n  - `addresses`: Transaction address\n\n  ```golang\n    client := archethic.NewAPIClient(\"http://localhost:4000\")\n    client.GetTransactionOwnerships(\"0000872D96130A2963F1195D1F85FC316AE966644F2E3EE45469C2A257F49C4631C2\")\n\n  ```\n\n  \u003c/details\u003e\n   \u003cbr/\u003e\n   \u003cdetails\u003e\n   \u003csummary\u003eKeychain / Wallet management\u003c/summary\u003e\n   \u003cbr/\u003e\n\n  #### NewKeychainTransaction(seed []byte, authorizedPublicKeys [][]byte) TransactionBuilder\n  Creates a new transaction to build a keychain by embedding the on-chain encrypted wallet.\n\n  - `seed` Keychain's seed\n  - `authorizedPublicKeys` List of authorized public keys able to decrypt the wallet\n\n  #### NewAccessTransaction(seed []byte, keychainAddress []byte) TransactionBuilder\n  Creates a new keychain access transaction to allow a seed and its key to access a keychain\n\n  - `seed` Keychain access's seed\n  - `keychainAddress` Keychain's tx address\n\n  #### GetKeychain(seed []byte, client APIClient) *Keychain\n  Retrieve a keychain from the keychain access transaction and decrypt the wallet to retrieve the services associated\n\n  - `seed` Keychain access's seed\n  - `client` the API client\n\n  ```go\n  client := archethic.NewAPIClient(\"http://localhost:4000\")\n  keychain := archethic.GetKeychain([]byte(\"seed\"), *client)\n  ```\n\n  Once retrieved the keychain provide the following methods:\n\n  #### (k Keychain) BuildTransaction(transaction TransactionBuilder, serviceName string, index uint8) TransactionBuilder\n  Generate `address`, `previousPublicKey`, `previousSignature` of the transaction and\n  serialize it using a custom binary protocol, based on the derivation path, curve and hash algo of the service given in param.\n\n  - `transaction` is an instance of `TransactionBuilder`\n  - `serviceName` is the service name to use for getting the derivation path, the curve and the hash algo\n  - `index` is the number of transactions in the chain, to generate the actual and the next public key (see the cryptography section)\n\n  Returns is the signed `TransactionBuilder`.\n\n  ```go\n\n  seed := []byte(\"seed\")\n\n  keychain := archethic.Keychain{Seed: seed, Version: 1, Services: map[string]Service{\n    \"uco\": {\n      DerivationPath: \"m/650'/0/0\",\n      Curve:          ED25519,\n      HashAlgo:       SHA256,\n    },\n  }}\n\n  tx := archethic.TransactionBuilder{TxType: TransferType}\n  ucoAddress, _ := hex.DecodeString(\"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\")\n  tx.AddUcoTransfer(\n    ucoAddress,\n    archethic.ToUint64(10.0, 8),\n  )\n\n  tx = keychain.BuildTransaction(tx, \"uco\", 0)\n\n  ```\n\n  #### (k Keychain) DeriveAddress(serviceName string, index uint8) []byte\n  Derive an address for the given service at the index given\n\n  - `service`: Service name to identify the derivation path to use\n  - `index`: Chain index to derive\n\n  ```go\n  seed := []byte(\"abcdefghijklmnopqrstuvwxyz\")\n\tkeychain := archethic.NewKeychain(seed)\n\tpublicKey, _ := keychain.DeriveKeypair(\"uco\", 0)\n\taddress := archethic.DeriveAddress(seed, 0, keychain.Services[\"uco\"].Curve, keychain.Services[\"uco\"].HashAlgo)\n  ```\n\n  #### (k Keychain) DeriveKeypair(serviceName string, index uint8) ([]byte, []byte)\n  Derive a keypair for the given service at the index given\n\n  - `service`: Service name to identify the derivation path to use\n  - `index`: Chain index to derive\n\n  ```go\n  seed := []byte(\"abcdefghijklmnopqrstuvwxyz\")\n\tkeychain := archethic.NewKeychain(seed)\n\tpublicKey, _ := keychain.DeriveKeypair(\"uco\", 0)\n  ```\n\n  #### (k Keychain) ToDID() DID\n  Return a Decentralized Identity document from the keychain. (This is used in the transaction's content of the keychain tx)\n\n  ```go\n  seed := []byte(\"abcdefghijklmnopqrstuvwxyz\")\n\tkeychain := archethic.NewKeychain(seed)\n\tdid := keychain.ToDID()\n  log.Println(string(did.ToJSON()))\n\n  {\n    \"@context\": [\n       \"https://www.w3.org/ns/did/v1\"\n    ],\n    \"id\": \"did:archethic:keychain_address\",\n    \"authentification\": servicesMaterials, //list of public keys of the services\n    \"verificationMethod\": servicesMaterials //list of public keys of the services\n  }\n  ```\n\n  #### (k *Keychain) AddService(name string, derivationPath string, curve Curve, hashAlgo HashAlgo)\n  Add a service into the keychain\n\n  - `name`: Name of the service to add\n  - `derivationPath`: Crypto derivation path\n  - `curve`: Elliptic curve to use\n  - `hashAlgo`: Hash algo\n\n  ```go\n  \tkeychain := archethic.NewKeychain([]byte(\"seed\"))\n\tkeychain.AddService(\"nft1\", \"m/650'/1/0\", archethic.ED25519, archethic.SHA256)\n\tlog.Println(keychain.Services)\n  //map[nft1:{m/650'/1/0 0 0} uco:{m/650'/0/0 1 0}]\n  ```\n\n   \u003cbr/\u003e\n\n\n## Running the tests\n\n```bash\ngo test\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchethic-foundation%2Flibgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farchethic-foundation%2Flibgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchethic-foundation%2Flibgo/lists"}