{"id":18519161,"url":"https://github.com/blockchaincommons/bcswiftfoundation","last_synced_at":"2025-04-09T08:32:04.204Z","repository":{"id":40598255,"uuid":"433386713","full_name":"BlockchainCommons/BCSwiftFoundation","owner":"BlockchainCommons","description":"A collection of useful primitives for cryptocurrency wallets.","archived":false,"fork":false,"pushed_at":"2024-10-06T06:54:42.000Z","size":4156,"stargazers_count":7,"open_issues_count":2,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T04:03:32.576Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BlockchainCommons.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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},"funding":{"github":["BlockchainCommons","ChristopherA"],"custom":"https://btcpay.blockchaincommons.com"}},"created_at":"2021-11-30T10:25:47.000Z","updated_at":"2024-10-06T06:54:36.000Z","dependencies_parsed_at":"2023-12-23T04:22:34.400Z","dependency_job_id":"91b1af39-7ff2-456a-a61a-785673dbda56","html_url":"https://github.com/BlockchainCommons/BCSwiftFoundation","commit_stats":null,"previous_names":[],"tags_count":86,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlockchainCommons%2FBCSwiftFoundation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlockchainCommons%2FBCSwiftFoundation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlockchainCommons%2FBCSwiftFoundation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlockchainCommons%2FBCSwiftFoundation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlockchainCommons","download_url":"https://codeload.github.com/BlockchainCommons/BCSwiftFoundation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248003264,"owners_count":21031760,"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":[],"created_at":"2024-11-06T17:15:32.361Z","updated_at":"2025-04-09T08:32:03.708Z","avatar_url":"https://github.com/BlockchainCommons.png","language":"Swift","readme":"# BCSwiftFoundation\n\nA collection of useful primitives for cryptocurrency wallets.\n\nOpinionated Swift wrapper around [LibWally](https://github.com/ElementsProject/libwally-core).\n\nSupports particular enhancements used by Blockchain Commons from our fork of libwally-core: [bc-libwally-core](https://github.com/blockchaincommons/bc-libwally-core), in the [bc-maintenance](https://github.com/BlockchainCommons/bc-libwally-core/tree/bc-maintenance) branch.\n\n# Dependencies\n\nDepends on [BCSwiftWally](https://github.com/BlockchainCommons/BCSwiftWally), which is a thin wrapper around LibWally that has a new build system for building a universal XCFramework for use with MacOSX, Mac Catalyst, iOS devices, and the iOS simulator across Intel and Apple Silicon (ARM).\n\n# Building\n\nAdd to your project like any other Swift Package.\n\n# Usage\n\n### Derive address from a seed:\n\n```swift\nimport BCFoundation\n\nlet mnemonic = BIP39(mnemonic: \"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about\")!\nlet seed = BIP39.Seed(bip39: mnemonic, passphrase: \"bip39 passphrase\")\nlet masterKey = try! HDKey(bip39Seed: seed)\nassert(masterKey.keyFingerprint.hex == \"7b343b65\")\nlet path = DerivationPath(string: \"m/44'/0'/0'\")!\nlet accountKey = try! HDKey(parent: masterKey, childDerivationPath: path)\nassert(accountKey.base58PrivateKey == \"xprv9z3bixmawU269r5jUAbWbVFDY3qN6LZdHH7r28C7gmZMXPfbN8o39622JvuyvQxBYPBMEtJNetWBCyy6hZXcAEubReyb95MnJQR5bAMiR2d\")\nassert(accountKey.base58PublicKey == \"xpub6D2x8UJUmqaPNLACaC8WxdBx65frVoHUeW3SpWbjF76LQBzjug7HgtLWACEbNoRubqXqM9y7t822g9RpEPPxmALG8tiZYVw5Ec66swihmUy\")\nassert(Bitcoin.Address(hdKey: accountKey, type: .payToWitnessPubKeyHash).description == \"bc1qtqq3hzwgswm56tt3h04ss8qmmttt6py9yj8h6c\")\n```\n\n### Derive address from an xpub:\n\n```swift\nimport BCFoundation\n\nlet accountKey = try! HDKey(base58: \"xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ\")\nlet receivePath = DerivationPath(string: \"0/0\")!\nlet receiveKey = try! HDKey(parent: accountKey, childDerivationPath: receivePath)\nlet address = Bitcoin.Address(hdKey: receiveKey, type: .payToPubKeyHash)\nassert(address.description == \"1BiCdXSDHyeXSzmx2paVPFVTrmyx7BeCGD\")\nassert(address.scriptPubKey.description == \"pkh:[OP_DUP OP_HASH160 757c05317fcb85e910c5f3e6cd9dc4d06b5d8321 OP_EQUALVERIFY OP_CHECKSIG]\")\n```\n\n### Parse an address:\n\n```swift\nimport BCFoundation\n\nlet address = Bitcoin.Address(string: \"bc1q6zwjfmhdl4pvhvfpv8pchvtanlar8hrhqdyv0t\")!\nassert(address.scriptPubKey.hex == \"0014d09d24eeedfd42cbb12161c38bb17d9ffa33dc77\")\nassert(address.scriptPubKey.type! == .wpkh)\nassert(address.scriptPubKey.description == \"wpkh:[OP_0 d09d24eeedfd42cbb12161c38bb17d9ffa33dc77]\")\n```\n\n### Create and sign a transaction:\n\n```swift\nimport BCFoundation\n\nlet pubKey = ECCompressedPublicKey(hex: \"03501e454bf00751f24b1b489aa925215d66af2234e3891c3b21a52bedb3cd711c\")!\nlet prevTx = TxHash(hex: \"0000000000000000000000000000000000000000000000000000000000000000\")!\nlet vout: UInt32 = 0\nlet legacyInputBytes: Int = 192\nlet amount1: Satoshi = 1000 + Satoshi(legacyInputBytes)\nlet scriptSig = ScriptSig(type: .payToPubKeyHash(pubKey))\nlet scriptPubKey1 = ScriptPubKey(hex: \"76a914bef5a2f9a56a94aab12459f72ad9cf8cf19c7bbe88ac\")!\nlet txInput1 = TxInput(prevTx: prevTx, vout: vout, amount: amount1, sig: .scriptSig(scriptSig), scriptPubKey: scriptPubKey1)\nlet hdKey = try! HDKey(base58: \"xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs\")\nlet txOutput = TxOutput(scriptPubKey: scriptPubKey1, amount: 1000)\nlet tx1 = Transaction(inputs: [txInput1], outputs: [txOutput])\nlet signedTx = tx1.signed(with: [hdKey])!\nassert(signedTx.inputs![0].isSigned)\nassert(signedTx.description == \"01000000010000000000000000000000000000000000000000000000000000000000000000000000006a47304402203d274300310c06582d0186fc197106120c4838fa5d686fe3aa0478033c35b97802205379758b11b869ede2f5ab13a738493a93571268d66b2a875ae148625bd20578012103501e454bf00751f24b1b489aa925215d66af2234e3891c3b21a52bedb3cd711cffffffff01e8030000000000001976a914bef5a2f9a56a94aab12459f72ad9cf8cf19c7bbe88ac00000000\")\nassert(signedTx.vbytes == legacyInputBytes - 1)\n```\n","funding_links":["https://github.com/sponsors/BlockchainCommons","https://github.com/sponsors/ChristopherA","https://btcpay.blockchaincommons.com"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblockchaincommons%2Fbcswiftfoundation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblockchaincommons%2Fbcswiftfoundation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblockchaincommons%2Fbcswiftfoundation/lists"}