Skip to content

Commit 2db2aaf

Browse files
Merge branch 'develop'
2 parents 876bdac + cb1cd12 commit 2db2aaf

File tree

13 files changed

+103
-24
lines changed

13 files changed

+103
-24
lines changed

c/include/in3/plugin.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,10 @@ typedef enum {
207207
* action context when retrieving the account of a signer.
208208
*/
209209
typedef struct sign_account_ctx {
210-
struct in3_ctx* ctx; /**< the context of the request in order report errors */
211-
address_t account; /**< the account to use for the signature */
212-
in3_signer_type_t signer_type; /**< the type of the signer used for this account.*/
210+
struct in3_ctx* ctx; /**< the context of the request in order report errors */
211+
uint8_t* accounts; /**< the account to use for the signature */
212+
int accounts_len; /**< number of accounts */
213+
in3_signer_type_t signer_type; /**< the type of the signer used for this account.*/
213214
} in3_sign_account_ctx_t;
214215

215216
// ----------- SIGN_PREPARE ---------------

c/src/core/client/plugin.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,10 @@ typedef enum {
207207
* action context when retrieving the account of a signer.
208208
*/
209209
typedef struct sign_account_ctx {
210-
struct in3_ctx* ctx; /**< the context of the request in order report errors */
211-
address_t account; /**< the account to use for the signature */
212-
in3_signer_type_t signer_type; /**< the type of the signer used for this account.*/
210+
struct in3_ctx* ctx; /**< the context of the request in order report errors */
211+
uint8_t* accounts; /**< the account to use for the signature */
212+
int accounts_len; /**< number of accounts */
213+
in3_signer_type_t signer_type; /**< the type of the signer used for this account.*/
213214
} in3_sign_account_ctx_t;
214215

215216
// ----------- SIGN_PREPARE ---------------

c/src/pay/zksync/zksync.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ static in3_ret_t send_provider_request(in3_ctx_t* parent, zksync_config_t* conf,
5858

5959
static in3_ret_t zksync_get_account(zksync_config_t* conf, in3_ctx_t* ctx, uint8_t** account) {
6060
if (!conf->account) {
61-
in3_sign_account_ctx_t sctx = {.ctx = ctx, .account = {0}};
62-
if (in3_plugin_execute_first(ctx, PLGN_ACT_SIGN_ACCOUNT, &sctx)) return ctx_set_error(ctx, "No account configured or signer set", IN3_ECONFIG);
63-
memcpy(conf->account = _malloc(20), sctx.account, 20);
61+
in3_sign_account_ctx_t sctx = {.ctx = ctx, .accounts = NULL, .accounts_len = 0};
62+
if (in3_plugin_execute_first(ctx, PLGN_ACT_SIGN_ACCOUNT, &sctx) || !sctx.accounts_len) {
63+
if (sctx.accounts) _free(sctx.accounts);
64+
return ctx_set_error(ctx, "No account configured or signer set", IN3_ECONFIG);
65+
}
66+
conf->account = (uint8_t*) sctx.accounts;
6467
}
6568

6669
if (account) *account = conf->account;

c/src/signer/pk-signer/signer.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ static bool add_key(in3_t* c, bytes32_t pk) {
7575
in3_sign_account_ctx_t ctx = {0};
7676

7777
for (in3_plugin_t* p = c->plugins; p; p = p->next) {
78-
if (p->acts & (PLGN_ACT_SIGN_ACCOUNT | PLGN_ACT_SIGN) && p->action_fn(p->data, PLGN_ACT_SIGN_ACCOUNT, &ctx) == IN3_OK && memcmp(ctx.account, address, 20) == 0) return false;
78+
if (p->acts & (PLGN_ACT_SIGN_ACCOUNT | PLGN_ACT_SIGN) && p->action_fn(p->data, PLGN_ACT_SIGN_ACCOUNT, &ctx) == IN3_OK && ctx.accounts_len) {
79+
bool is_same_address = memcmp(ctx.accounts, address, 20) == 0;
80+
_free(ctx.accounts);
81+
if (is_same_address) return false;
82+
}
7983
}
8084

8185
eth_set_pk_signer(c, pk);
@@ -104,7 +108,9 @@ static in3_ret_t eth_sign_pk(void* data, in3_plugin_act_t action, void* action_c
104108
// generate the address from the key
105109
in3_sign_account_ctx_t* ctx = action_ctx;
106110
ctx->signer_type = SIGNER_ECDSA;
107-
memcpy(ctx->account, k->account, 20);
111+
ctx->accounts = _malloc(20);
112+
ctx->accounts_len = 1;
113+
memcpy(ctx->accounts, k->account, 20);
108114
return IN3_OK;
109115
}
110116

@@ -182,11 +188,17 @@ static in3_ret_t pk_rpc(void* data, in3_plugin_act_t action, void* action_ctx) {
182188
if (strcmp(method, "eth_accounts") == 0) {
183189
sb_t* sb = in3_rpc_handle_start(ctx);
184190
bool first = true;
185-
in3_sign_account_ctx_t sc = {0};
191+
in3_sign_account_ctx_t sc = {.ctx = ctx->ctx, .accounts = NULL, .accounts_len = 0, .signer_type = 0};
186192
for (in3_plugin_t* p = ctx->ctx->client->plugins; p; p = p->next) {
187193
if (p->acts & PLGN_ACT_SIGN_ACCOUNT && p->action_fn(p->data, PLGN_ACT_SIGN_ACCOUNT, &sc) == IN3_OK) {
188-
sb_add_rawbytes(sb, first ? "[\"0x" : "\",\"0x", bytes(sc.account, 20), 20);
189-
first = false;
194+
for (int i = 0; i < sc.accounts_len; i++) {
195+
sb_add_rawbytes(sb, first ? "[\"0x" : "\",\"0x", bytes(sc.accounts + i * 20, 20), 20);
196+
first = false;
197+
}
198+
if (sc.accounts) {
199+
_free(sc.accounts);
200+
sc.accounts_len = 0;
201+
}
190202
}
191203
}
192204
sb_add_chars(sb, first ? "[]" : "\"]");

c/src/verifier/eth1/basic/sign_tx.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ static in3_ret_t get_from_address(d_token_t* tx, in3_ctx_t* ctx, address_t res)
113113
// if it is not specified, we rely on the from-address of the signer.
114114
if (!in3_plugin_is_registered(ctx->client, PLGN_ACT_SIGN_ACCOUNT)) return ctx_set_error(ctx, "missing from address in tx", IN3_EINVAL);
115115

116-
in3_sign_account_ctx_t actx = {.ctx = ctx, .account = {0}};
116+
in3_sign_account_ctx_t actx = {.ctx = ctx, .accounts = NULL, .accounts_len = 0};
117117
TRY(in3_plugin_execute_first(ctx, PLGN_ACT_SIGN_ACCOUNT, &actx))
118-
memcpy(res, actx.account, 20);
118+
if (!actx.accounts) return ctx_set_error(ctx, "no from address found", IN3_EINVAL);
119+
memcpy(res, actx.accounts, 20);
120+
_free(actx.accounts);
119121
return IN3_OK;
120122
}
121123

c/test/vm_runner.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ int main(int argc, char* argv[]) {
209209

210210
in3_log_set_level(LOG_DEBUG);
211211
in3_log_set_prefix("");
212+
in3_log_set_quiet(false);
212213

213214
for (i = 1; i < argc; i++) {
214215
if (strcmp(argv[i], "-t") == 0)

dotnet/ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ release_nuget:
9494
- dotnet_macos
9595
script:
9696
- cd dotnet
97-
- dotnet pack -c Release -p:version=${CI_COMMIT_TAG}
98-
- dotnet nuget push In3/bin/Release/Blockchains.In3.${CI_COMMIT_TAG}.nupkg -k {NUGET_GALLERY_API_KEY} -s https://api.nuget.org/v3/index.json
97+
- export NUGET_VERSION=$(echo "$CI_COMMIT_TAG" | cut -c 2-)
98+
- dotnet pack -c Release -p:version=${NUGET_VERSION}
99+
- dotnet nuget push In3/bin/Release/Blockchains.In3.${NUGET_VERSION}.nupkg -k {NUGET_GALLERY_API_KEY} -s https://api.nuget.org/v3/index.json
99100
artifacts:
100101
paths:
101-
- dotnet/In3/bin/Release/Blockchains.In3.${CI_COMMIT_TAG}.nupkg
102+
- dotnet/In3/bin/Release/Blockchains.In3.${NUGET_VERSION}.nupkg

wasm/src/in3.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ const aliases = { kovan: '0x2a', tobalaba: '0x44d', main: '0x1', ipfs: '0x7d0',
150150
*/
151151
class IN3 {
152152

153+
set signer(signer) {
154+
this._signer = signer
155+
if (signer && signer.getAccounts)
156+
this.registerPlugin(signer)
157+
}
158+
get signer() {
159+
return this._signer
160+
}
161+
153162
_ensure_ptr_sync() {
154163
if (this.ptr) return
155164
let chainId = this.config && this.config.chainId
@@ -223,7 +232,7 @@ class IN3 {
223232
registerPlugin(plgn) {
224233
let action = 0
225234
if (plgn.term) action |= 0x2
226-
if (plgn.getAccount) action |= 0x20
235+
if (plgn.getAccounts) action |= 0x20
227236
if (plgn.handleRPC) action |= 0x100
228237
if (plgn.verifyRPC) action |= 0x200
229238
if (plgn.cacheGet) action |= 0x800
@@ -235,7 +244,7 @@ class IN3 {
235244
this.plugins.push(plgn)
236245
}
237246

238-
if (this.ptr)
247+
if (this.ptr)
239248
in3w.ccall('wasm_register_plugin', 'number', ['number', 'number', 'number'], [this.ptr, action, index]);
240249
}
241250

@@ -334,7 +343,7 @@ class IN3 {
334343
return res.result
335344
}
336345

337-
sendSyncRPC(method, params = []) {
346+
execLocal(method, params = []) {
338347
this._ensure_ptr_sync();
339348
if (this.needsSetConfig) this.setConfig()
340349
const r = in3w.ccall('in3_create_request_ctx', 'number', ['number', 'string'], [this.ptr, JSON.stringify({ method, params })]);

wasm/src/in3_util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,10 @@ class SimpleSigner {
568568
if (pks) pks.forEach(_ => this.addAccount(_))
569569
}
570570

571+
getAccounts() {
572+
return Object.keys(this.accounts)
573+
}
574+
571575
addAccount(pk) {
572576
const adr = private2address(pk)
573577
this.accounts[adr] = toBuffer(pk)

wasm/src/index.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ export default class IN3Generic<BigIntType, BufferType> {
456456
*
457457
* @param method the method to call.
458458
*/
459-
public sendSyncRPC(method: string, params?: any[]): any;
459+
public execLocal(method: string, params?: any[]): any;
460460

461461
/**
462462
* disposes the Client. This must be called in order to free allocated memory!
@@ -640,6 +640,9 @@ export declare interface Signer<BigIntType, BufferType> {
640640
/** returns true if the account is supported (or unlocked) */
641641
canSign(address: Address): Promise<boolean>
642642

643+
/** returns all addresses managed by the signer. */
644+
getAccounts(): Address[]
645+
643646
/**
644647
* signing of any data.
645648
* if hashFirst is true the data should be hashed first, otherwise the data is the hash.
@@ -652,6 +655,10 @@ export declare class SimpleSigner<BigIntType, BufferType> implements Signer<BigI
652655
[ac: string]: BufferType;
653656
};
654657
constructor(...pks: (Hash | BufferType)[]);
658+
659+
/** returns all addresses managed by the signer. */
660+
getAccounts(): Address[]
661+
/** adds a private key to the signer. */
655662
addAccount(pk: Hash): string;
656663
/** optiional method which allows to change the transaction-data before sending it. This can be used for redirecting it through a multisig. */
657664
prepareTransaction?: (client: IN3Generic<BigIntType, BufferType>, tx: Transaction) => Promise<Transaction>

0 commit comments

Comments
 (0)