Ecdsa.sign_loop: def of bend-collections@1.0.0.0 Import: import bend-collections@1.0.0.0/src/crypto/secp256k1/ecdsa.bend as Ecdsa Lines 109-122 of bend-collections@1.0.0.0/src/crypto/secp256k1/ecdsa.bend: https://jend.leeeet.dev/read.txt?path=bend-collections@1.0.0.0/src/crypto/secp256k1/ecdsa.bend&start_line=109&end_line=122 import Base # step h: the candidate V; a k outside [1, n - 1], or one giving r = 0 or # s = 0 (SEC 1 section 4.1.3 steps 3 and 6), is replaced by the next # candidate: K = HMAC_K(V || 0x00), V = HMAC_K(V), V = HMAC_K(V). The loop # stops after `fuel` candidates (the chance that even 2 are needed is below # 2^-127). def sign_loop(fuel: Nat, +z: List<&2, Nat>, +d: List<&2, Nat>, +k: List<&2, U32>, +v: List<&2, U32>, att: Attempt) -> Maybe<&2, Signature>: match fuel att: case 0n ARetry{}: None{} case 0n ADone{sig}: Some{sig} case 1n+f ARetry{}: +k2 = hmac(k, cat(v, [0])) +v3 = hmac(k2, hmac(k2, v)) sign_loop(f, z, d, k2, v3, attempt(z, d, v3)) case 1n+f ADone{sig}: Some{sig} Uses (9): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Maybe https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=bend-collections@1.0.0.0/src/crypto/secp256k1/ecdsa.bend&name=Attempt https://jend.leeeet.dev/definition.txt?path=bend-collections@1.0.0.0/src/crypto/secp256k1/ecdsa.bend&name=Signature https://jend.leeeet.dev/definition.txt?path=bend-collections@1.0.0.0/src/crypto/secp256k1/ecdsa.bend&name=attempt https://jend.leeeet.dev/definition.txt?path=bend-collections@1.0.0.0/src/crypto/secp256k1/ecdsa.bend&name=cat https://jend.leeeet.dev/definition.txt?path=bend-collections@1.0.0.0/src/crypto/secp256k1/ecdsa.bend&name=hmac