{"id":13718232,"url":"https://github.com/tgalal/motoko-bitcoin","last_synced_at":"2025-06-29T17:33:13.539Z","repository":{"id":39789116,"uuid":"456218454","full_name":"tgalal/motoko-bitcoin","owner":"tgalal","description":"Bitcoin library for Motoko","archived":false,"fork":false,"pushed_at":"2023-02-14T22:57:18.000Z","size":213,"stargazers_count":20,"open_issues_count":3,"forks_count":14,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-11T05:41:18.560Z","etag":null,"topics":["base58","bitcoin","cryptography","hmac","ripemd160","secp256k1"],"latest_commit_sha":null,"homepage":"","language":"Modelica","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tgalal.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}},"created_at":"2022-02-06T17:18:20.000Z","updated_at":"2025-04-04T23:41:24.000Z","dependencies_parsed_at":"2024-01-07T18:05:17.297Z","dependency_job_id":"5ab8be05-52b4-487a-8ea2-6238e0865071","html_url":"https://github.com/tgalal/motoko-bitcoin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tgalal/motoko-bitcoin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tgalal%2Fmotoko-bitcoin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tgalal%2Fmotoko-bitcoin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tgalal%2Fmotoko-bitcoin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tgalal%2Fmotoko-bitcoin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tgalal","download_url":"https://codeload.github.com/tgalal/motoko-bitcoin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tgalal%2Fmotoko-bitcoin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262637629,"owners_count":23341163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["base58","bitcoin","cryptography","hmac","ripemd160","secp256k1"],"created_at":"2024-08-03T00:08:22.686Z","updated_at":"2025-06-29T17:33:13.491Z","avatar_url":"https://github.com/tgalal.png","language":"Modelica","funding_links":[],"categories":["Libraries"],"sub_categories":["Cryptography"],"readme":"# Algorithms for Bitcoin Integration in Motoko\n\n## Testing\n\nPull dependencies\n\n```\ngit submodule update --init\n```\n\nRun all tests\n\n```\nmake test\n```\n\n## Usage\n\nBase58:\n\n```motoko\nimport Base58 \"src/Base58\";\n\nlet encoded : Text = Base58.encode([ /* Nat8 data */ ]);\n```\n\nBase58Check:\n\n```motoko\nimport Base58Check \"src/Base58Check\";\n\nlet encoded : Text = Base58Check.encode([ /* Nat8 data */ ]);\n```\n\nHMAC:\n\n```motoko\nimport Hmac \"src/Hmac\";\n\nlet key : [Nat8] = [ /* Key bytes */ ];\n\n// HMAC-SHA256\nlet hmacSha256 : Hmac.Hmac = Hmac.sha256(key);\nhmacSha256.write([ /* Nat8 data */ ]);\nvar result : [Nat8] = hmacSha256.sum();\n\n// HMAC-SHA512\nlet hmacSha512 : Hmac.Hmac = Hmac.sha512(key);\nhmacSha512.write([ /* Nat8 data */ ]);\nresult := hmacSha512.sum();\n\n// HMAC-X\nlet hmacCustomDigest : Hmac.Hmac = Hmac.new(key, object {\n  public let blockSize : Nat = 64;\n  public func create() : Hmac.Digest = object {\n    public func write(data : [Nat8]) { /* Process input */ };\n    public func sum() : [Nat8] = [ /* Compute sum */ ];\n  };\n});\nhmacCustomDigest.write([ /* Nat8 data */ ]);\nresult := hmacCustomDigest.sum();\n```\n\nRIPEMD160:\n\n```motoko\nimport Ripemd160 \"src/Ripemd160\";\n\nlet digest : Ripemd160.Digest = Ripemd160.Digest();\ndigest.write([ /* Nat8 data */ ]);\ndigest.write([ /* Nat8 data */ ]);\nlet result : [Nat8] = digest.sum();\n```\n\nEC\n\n```motoko\nimport Jacobi \"src/ec/Jacobi\";\nimport Affine \"src/ec/Affine\";\nimport Curves \"src/ec/Curves\";\n\n// Get secp256k1 curve parameters.\nlet secp256k1 : Curves.Curve = Curves.secp256k1;\nlet Fp = secp256k1.Fp;\n\n// Create affine point on the secp256k1 curve\nlet basePointAffine : Affine.Point = #point (Fp(secp256k1.gx), Fp(secp256k1.gy), secp256k1);\n// Convert to Jacobi point\nlet basePointJacobi : Jacobi.Point = Jacobi.fromAffine(basePointAffine);\n\n// Scalar multiplication\nlet mul1 = Jacobi.mul(basePointJacobi, 1234);\nlet mul2 = Jacobi.mulBase(1234, Curves.secp256k1);\n\nassert(Jacobi.isEqual(mul1, mul2));\n```\n\nBip32\n\n```motoko\nimport Bip32 \"src/Bip32\";\n\nlet rootKey : ?Bip32.ExtendedPublicKey = Bip32.parse(\"xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8\", null);\n\ndo ? {\n  let derived : ?Bip32.ExtendedPublicKey = rootKey!.derivePath(#text \"m/1/2/3\");\n  derived!;\n};\n\n```\n\nBech32:\n\n```motoko\nimport Bech32 \"src/Bech32\";\n\nBech32.encode(\"bc\", [ /* Nat8 data */ ], #BECH32);\nBech32.decode(\"bc\", \"bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4\");\n```\n\nSegwit:\n\n```motoko\nimport Segwit \"src/Segwit\";\n\nSegwit.encode(\"bc\", /* WitnessProgram */ );\nSegwit.decode(\"bc\", \"BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4\");\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftgalal%2Fmotoko-bitcoin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftgalal%2Fmotoko-bitcoin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftgalal%2Fmotoko-bitcoin/lists"}