PageSourceSearch

https://noir-lang.org/docs/assets/js/2e0314a4.0ce78ffd.js

js noir-lang.org collected 2026-10-03 22:53:35 UTC 10,590 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkdocs=globalThis.webpackChunkdocs||[]).push([[2867],{53352(e,n,i){i.r(n),i.d(n,{assets:()=>c,contentTitle:()=>s,default:()=>p,frontMatter:()=>o,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"project_structure/dependencies","title":"Dependencies","description":"Learn how to specify and manage dependencies in Nargo, allowing you to upload packages to GitHub and use them easily in your project.","source":"@site/versioned_docs/version-v1.0.0-rc.0/project_structure/dependencies.md","sourceDirName":"project_structure","slug":"/project_structure/dependencies","permalink":"/docs/v1.0.0-rc.0/project_structure/dependencies","draft":false,"unlisted":false,"editUrl":"https://github.com/noir-lang/noir/edit/master/docs/versioned_docs/version-v1.0.0-rc.0/project_structure/dependencies.md","tags":[],"version":"v1.0.0-rc.0","frontMatter":{"title":"Dependencies","description":"Learn how to specify and manage dependencies in Nargo, allowing you to upload packages to GitHub and use them easily in your project.","keywords":["Nargo","dependencies","GitHub","package management","versioning"]},"sidebar":"sidebar","previous":{"title":"Crates and Packages","permalink":"/docs/v1.0.0-rc.0/project_structure/crates_and_packages"},"next":{"title":"Modules","permalink":"/docs/v1.0.0-rc.0/project_structure/modules"}}');var a=i(74848),t=i(28453);const o={title:"Dependencies",description:"Learn how to specify and manage dependencies in Nargo, allowing you to upload packages to GitHub and use them easily in your project.",keywords:["Nargo","dependencies","GitHub","package management","versioning"]},s=void 0,c={},d=[{value:"Specifying a dependency",id:"specifying-a-dependency",level:2},{value:"Specifying a local dependency",id:"specifying-a-local-dependency",level:2},{value:"Importing dependencies",id:"importing-dependencies",level:2},{value:"Dependencies of Dependencies",id:"dependencies-of-dependencies",level:2},{value:"Available Libraries",id:"available-libraries",level:2}];function l(e){const n={a:"a",admonition:"admonition",code:"code",em:"em",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,t.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.p,{children:"Nargo allows you to upload packages to GitHub and use them as dependencies."}),"\n",(0,a.jsx)(n.h2,{id:"specifying-a-dependency",children:"Specifying a dependency"}),"\n",(0,a.jsxs)(n.p,{children:["Specifying a dependency requires a ",(0,a.jsx)(n.code,{children:"tag"})," to a specific commit and a ",(0,a.jsx)(n.code,{children:"git"})," url to the url containing the package."]}),"\n",(0,a.jsx)(n.admonition,{type:"note",children:(0,a.jsxs)(n.p,{children:["Without a ",(0,a.jsx)(n.code,{children:"tag"})," , there would be no versioning and dependencies would change each time you compile your project."]})}),"\n",(0,a.jsxs)(n.p,{children:["For example, to add the ",(0,a.jsx)(n.a,{href:"https://github.com/noir-lang/noir-bignum",children:"bignum library"})," to your project, add it to ",(0,a.jsx)(n.em,{children:"Nargo.toml"}),":"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-toml",children:'# Nargo.toml\n\n[dependencies]\nbignum = { tag = "v0.8.0", git = "https://github.com/noir-lang/noir-bignum" }\n'})}),"\n",(0,a.jsx)(n.p,{children:"If the module is in a subdirectory, you can define a subdirectory in your git repository, for example:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-toml",children:'# Nargo.toml\n\n[dependencies]\nblob = {tag ="v1.2.1", git = "https://github.com/AztecProtocol/aztec-packages", directory = "noir-projects/noir-protocol-circuits/crates/blob"}\n'})}),"\n",(0,a.jsxs)(n.admonition,{type:"tip",children:[(0,a.jsxs)(n.p,{children:["Instead of editing ",(0,a.jsx)(n.em,{children:"Nargo.toml"})," by hand, you can let ",(0,a.jsx)(n.code,{children:"nargo add"})," write the entry for you. It downloads the dependency, verifies it, and names the entry after the dependency's own package:"]}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-sh",children:"nargo add --git https://github.com/noir-lang/noir-bignum --tag v0.8.0\n"})}),(0,a.jsxs)(n.p,{children:["Add ",(0,a.jsx)(n.code,{children:"--directory <subdir>"})," when the package lives in a subdirectory of the repository."]})]}),"\n",(0,a.jsx)(n.admonition,{type:"info",children:(0,a.jsxs)(n.p,{children:["Currently, there are no requirements applied on the contents of ",(0,a.jsx)(n.code,{children:"tag"}),". Requirements based on semver 2.0 guidelines could be introduced in the future."]})}),"\n",(0,a.jsx)(n.h2,{id:"specifying-a-local-dependency",children:"Specifying a local dependency"}),"\n",(0,a.jsx)(n.p,{children:"You can also specify dependencies that are local to your machine."}),"\n",(0,a.jsx)(n.p,{children:"For example, this file structure has a library and binary crate"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-tree",children:"\u251c\u2500\u2500 binary_crate\n\u2502\xa0\xa0 \u251c\u2500\u2500 Nargo.toml\n\u2502\xa0\xa0 \u2514\u2500\u2500 src\n\u2502\xa0\xa0     \u2514\u2500\u2500 main.nr\n\u2514\u2500\u2500 lib_a\n    \u251c\u2500\u2500 Nargo.toml\n    \u2514\u2500\u2500 src\n        \u2514\u2500\u2500 lib.nr\n"})}),"\n",(0,a.jsx)(n.p,{children:"Inside of the binary crate, you can specify:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-toml",children:'# Nargo.toml\n\n[dependencies]\nlib_a = { path = "../lib_a" }\n'})}),"\n",(0,a.jsx)(n.admonition,{type:"tip",children:(0,a.jsxs)(n.p,{children:["This entry can also be added with ",(0,a.jsx)(n.code,{children:"nargo add --path ../lib_a"})," instead of editing ",(0,a.jsx)(n.em,{children:"Nargo.toml"})," by hand."]})}),"\n",(0,a.jsx)(n.h2,{id:"importing-dependencies",children:"Importing dependencies"}),"\n",(0,a.jsx)(n.p,{children:"You can import a dependency to a Noir file using the following syntax. For example, to import the\necrecover-noir library and local lib_a referenced above:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-rust",children:"use ecrecover;\nuse lib_a;\n"})}),"\n",(0,a.jsx)(n.p,{children:"You can also import only the specific parts of dependency that you want to use, like so:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-rust",children:"use std::hash::blake3;\nuse std::embedded_curve_ops::fixed_base_scalar_mul;\n"})}),"\n",(0,a.jsx)(n.p,{children:"Lastly, You can import multiple items in the same line by enclosing them in curly braces:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-rust",children:"use std::hash::{blake2s, blake3};\n"})}),"\n",(0,a.jsxs)(n.p,{children:["We don't have a way to consume libraries from inside a ",(0,a.jsx)(n.a,{href:"/docs/v1.0.0-rc.0/project_structure/workspaces",children:"workspace"})," as external dependencies right now."]}),"\n",(0,a.jsxs)(n.p,{children:["Inside a workspace, these are consumed as ",(0,a.jsx)(n.code,{children:'{ path = "../to_lib" }'})," dependencies in ",(0,a.jsx)(n.em,{children:"Nargo.toml"}),"."]}),"\n",(0,a.jsx)(n.h2,{id:"dependencies-of-dependencies",children:"Dependencies of Dependencies"}),"\n",(0,a.jsx)(n.p,{children:"Note that when you import a dependency, you also get access to all of the dependencies of that package."}),"\n",(0,a.jsxs)(n.p,{children:["For example, the ",(0,a.jsx)(n.a,{href:"https://github.com/resurgencelabs/phy_vector",children:"phy_vector"})," library imports an ",(0,a.jsx)(n.a,{href:"https://github.com/resurgencelabs/fraction",children:"fraction"})," library. If you're importing the phy_vector library, then you can access the functions in fractions library like so:"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-rust",children:"use phy_vector;\n\nfn main(x : u32, y : pub u32) {\n  //...\n  let f = phy_vector::fraction::toFraction(true, 2, 1);\n  //...\n}\n"})}),"\n",(0,a.jsx)(n.h2,{id:"available-libraries",children:"Available Libraries"}),"\n",(0,a.jsxs)(n.p,{children:["Noir does not currently have an official package manager. You can find a list of available Noir libraries in the ",(0,a.jsx)(n.a,{href:"https://github.com/noir-lang/awesome-noir#libraries",children:"awesome-noir repo here"}),"."]}),"\n",(0,a.jsx)(n.p,{children:"Some libraries that are available today include:"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://github.com/noir-lang/noir/tree/master/noir_stdlib",children:"Standard Library"})," - the Noir Standard Library"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://github.com/aragonzkresearch/noir-trie-proofs",children:"Ethereum Storage Proof Verification"})," - a library that contains the primitives necessary for RLP decoding (in the form of look-up table construction) and Ethereum state and storage proof verification (or verification of any trie proof involving 32-byte long keys)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://github.com/shuklaayush/noir-bigint",children:"BigInt"})," - a library that provides a custom BigUint56 data type, allowing for computations on large unsigned integers"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://github.com/colinnielsen/ecrecover-noir/tree/main",children:"ECrecover"})," - a library to verify an ECDSA signature and return the source Ethereum address"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://github.com/vocdoni/smtverifier-noir/tree/main",children:"Sparse Merkle Tree Verifier"})," - a library for verification of sparse Merkle trees"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://github.com/resurgencelabs/signed_int",children:"Signed Int"})," - a library for accessing a custom Signed Integer data type, allowing access to negative numbers on Noir"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://github.com/resurgencelabs/fraction",children:"Fraction"})," - a library for accessing fractional number data type in Noir, allowing results that aren't whole numbers"]}),"\n"]})]})}function p(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(l,{...e})}):l(e)}},28453(e,n,i){i.d(n,{R:()=>o,x:()=>s});var r=i(96540);const a={},t=r.createContext(a);function o(e){const n=r.useContext(t);return r.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function s(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(t.Provider,{value:n},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.