bool bkeys_pubkey_append(struct bp_keystore *ks, const bu160_t *key_id, GString *scriptSig) { struct bp_key key; bp_key_init(&key); if (!bkeys_key_get(ks, key_id, &key)) return false; void *pubkey = NULL; size_t pk_len = 0; if (!bp_pubkey_get(&key, &pubkey, &pk_len)) return false; bsp_push_data(scriptSig, pubkey, pk_len); free(pubkey); /* no bp_key_free(&key), as bkeys_key_get() returns a ref */ return true; }
static bool sign1(const bu160_t *key_id, struct bp_keystore *ks, const bu256_t *hash, int nHashType, cstring *scriptSig) { struct bp_key key; bool rc = false; bp_key_init(&key); /* find private key in keystore */ if (!bkeys_key_get(ks, key_id, &key)) goto out; void *sig = NULL; size_t siglen = 0; /* sign hash with private key */ if (!bp_sign(&key, hash, sizeof(*hash), &sig, &siglen)) goto out; /* append nHashType to signature */ unsigned char ch = (unsigned char) nHashType; sig = realloc(sig, siglen + 1); memcpy(sig + siglen, &ch, 1); siglen++; /* append signature to scriptSig */ bsp_push_data(scriptSig, sig, siglen); free(sig); rc = true; out: bp_key_free(&key); return rc; }