/** * Add signature to sealed (before) contract. Do not deserializing or changing contract bytes, * but will change sealed and hashId. * * Useful if you got contracts from third-party (another computer) and need to sign it. * F.e. contracts that should be sign with two persons. * * @param privateKey - key to sign contract will with */ public void addSignatureToSeal(PrivateKey privateKey) { Set<PrivateKey> keys = new HashSet<>(); keys.add(privateKey); addSignatureToSeal(keys); }
private static void doSign() throws IOException { String source = (String) options.valueOf("sign"); List<String> names = (List) options.valuesOf("output"); Contract c = Contract.fromPackedTransaction(Files.readAllBytes(Paths.get(source))); if(c != null) { keysMap().values().forEach( k -> c.addSignatureToSeal(k)); String name; if(names.size() > 0) { name = names.get(0); } else { String suffix = "_signedby_"+String.join("_",c.getSealedByKeys().stream().map(k->k.getShortAddress().toString()).collect(Collectors.toSet())); name = new FilenameTool(source).addSuffixToBase(suffix).toString(); } saveContract(c,name,true,false); } finish(); }
c.addSignatureToSeal(keys); swapContract.addSignatureToSeal(keys);
/** * Add signature to sealed (before) contract. Do not deserializing or changing contract bytes, * but will change sealed and hashId. * * Useful if you got contracts from third-party (another computer) and need to sign it. * F.e. contracts that should be sign with two persons. * * @param privateKeys - key to sign contract will with */ public void addSignatureToSeal(Set<PrivateKey> privateKeys) { if (sealedBinary == null) throw new IllegalStateException("failed to add signature: sealed binary does not exist"); keysToSignWith.addAll(privateKeys); Binder data = Boss.unpack(sealedBinary); byte[] contractBytes = data.getBinaryOrThrow("data"); for (PrivateKey key : privateKeys) { byte[] signature = ExtendedSignature.sign(key, contractBytes); addSignatureToSeal(signature,key.getPublicKey()); } }
/** * Seal contract to binary. This call adds signatures from {@link #getKeysToSignWith()} * @return contract's sealed unicapsule */ public byte[] seal() { Object forPack = BossBiMapper.serialize( Binder.of( "contract", this, "revoking", revokingItems.stream() .map(i -> i.getId()) .collect(Collectors.toList()), "new", newItems.stream() .map(i -> i.getId(true)) .collect(Collectors.toList()) ) ); byte[] theContract = Boss.pack( forPack ); List<byte[]> signatures = new ArrayList<>(); Binder result = Binder.of( "type", "unicapsule", "version", 3, "data", theContract, "signatures", signatures ); setOwnBinary(result); addSignatureToSeal(keysToSignWith); return sealedBinary; }
notaryContract.addSignatureToSeal(issuerKeys);
/** * Creates a token contract with possible additional emission. * <br><br> * The service creates a simple token contract with issuer, creator and owner roles; * with change_owner permission for owner, revoke permissions for owner and issuer and split_join permission for owner. * Split_join permission has by default following params: "minValue" for min_value and min_unit, "amount" for field_name, * "state.origin" for join_match_fields. * Modify_data permission has by default following params: fields: "amount". * By default expires at time is set to 60 months from now. * * @param issuerKeys is issuer private keys. * @param ownerKeys is owner public keys. * @param amount is start token number. * @param minValue is minimum token value. * @return signed and sealed contract, ready for register. */ @Deprecated public synchronized static Contract createTokenContractWithEmission(Set<PrivateKey> issuerKeys, Set<PublicKey> ownerKeys, BigDecimal amount, BigDecimal minValue) { Contract tokenContract = createTokenContract(issuerKeys, ownerKeys, amount, minValue); RoleLink issuerLink = new RoleLink("issuer_link", "issuer"); tokenContract.registerRole(issuerLink); HashMap<String, Object> fieldsMap = new HashMap<>(); fieldsMap.put("amount", null); Binder modifyDataParams = Binder.of("fields", fieldsMap); ModifyDataPermission modifyDataPermission = new ModifyDataPermission(issuerLink, modifyDataParams); tokenContract.addPermission(modifyDataPermission); tokenContract.seal(); tokenContract.addSignatureToSeal(issuerKeys); return tokenContract; }
c.addSignatureToSeal(keys); contractHashId.put(c.getTransactional().getId(), c.getId()); c.addSignatureToSeal(keys);
public synchronized Contract finishSwap_wrongKey(Contract swapContract, Set<PrivateKey> keys, PrivateKey wrongKey) { List<Contract> swappingContracts = (List<Contract>) swapContract.getNew(); // looking for contract that will be own for (Contract c : swappingContracts) { boolean willBeMine = c.getOwner().isAllowedForKeys(keys); System.out.println("willBeMine: " + willBeMine + " " + c.getSealedByKeys().size()); if(willBeMine) { c.addSignatureToSeal(wrongKey); } } swapContract.seal(); return swapContract; }
twoSignContract.addSignatureToSeal(stepaPrivateKeys); twoSignContract.addSignatureToSeal(martyPrivateKeys);
c.addSignatureToSeal(wrongKey); contractHashId = c.getId(); c.addSignatureToSeal(wrongKey);
swapContract.getNew().get(iHack).getTransactional().getReferences().get(0).contract_id = HashId.createRandom(); swapContract.getNew().get(iHack).seal(); swapContract.getNew().get(iHack).addSignatureToSeal(stepaPrivateKeys); swapContract.seal();
newLamborghini.addSignatureToSeal(stepaPrivateKeys); swapContract.removeAllSignatures(); swapContract.addSignatureToSeal(stepaPrivateKeys);
twoSignContract.addSignatureToSeal(stepaPrivateKeys); twoSignContract.addSignatureToSeal(martyPrivateKeys);
contractImported.addSignatureToSeal(creatorPrivateKey); contractImported.addSignatureToSeal(TestKeys.privateKey(0));
newLamborghini.addSignatureToSeal(martyPrivateKeys);
tokenContract.addSignatureToSeal(issuerKeys);
swapContract.addNewItems(martyCoinsSplit, stepaCoinsSplit); swapContract.seal(); swapContract.addSignatureToSeal(martyPrivateKeys);
shareContract.addSignatureToSeal(issuerKeys);
notaryContract.addSignatureToSeal(issuerKeys);