Phantom wallet addresses not making sense - solana-web3js

If I import a seed phrase with #solana/web3.js I seem to get different public address than the ones generated by Phantom wallet when I import the same seed phrase. Anyone any idea why?
const seed = Bip39.mnemonicToSeedSync("<12 word phrase>").slice(0, 32);
const mint_authority = web3.Keypair.fromSeed(seed)
do I need to do anything with derivation paths so that addresses generated match those of Phantom wallet ?

You can use this code.
It runs correctly in my side.
seed_bytes = Bip39SeedGenerator(cfg.ETH_TEMP_MNEMONIC).Generate()
bip44_mst_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.SOLANA)
for i in range(100):
bip44_acc_ctx = bip44_mst_ctx.Purpose().Coin().Account(i)
bip44_chg_ctx = bip44_acc_ctx.Change(Bip44Changes.CHAIN_EXT)
new_wallet = WalletData()
new_wallet.public_key = bip44_chg_ctx.PublicKey().ToAddress()
new_wallet.private_key = Base58Encoder.Encode(
bip44_chg_ctx.PrivateKey().Raw().ToBytes() + bip44_chg_ctx.PublicKey().RawCompressed().ToBytes()[1:]
)

Related

PowerPoint REST API?

I'm looking for a REST API for generating PowerPoint slides... does anyone have any suggestions?
Realize this wouldn't be too difficult to implement, but we're trying to avoid building noncore functionality we could get from a third party.
Basically, we want to send a JSON blob and get back the generated slide.
Think this is a related question:
Is there an API to make a MS Office 365 Powerpoint presentation programmatically?
Thanks for your help!
You can try using Aspose.Slides Cloud for your purposes. This product provides REST-based APIs for many programming languages (C#, Java, PHP, Ruby, Python, Node.js, C++, Go, Perl, Swift), platforms and environments. With this product, you can use both Aspose file storages and third-party storages. Docker containers can also be used for working with Aspose.Slides Cloud.
This product does not support adding contents to presentations from JSON files but it provides many features for generating contents. It also provides features to add contents to presentations from HTML and PDF documents. The following Python sample code shows you how to add a WordArt object to a new presentation, for example.
import asposeslidescloud
from asposeslidescloud.apis.slides_api import SlidesApi
from asposeslidescloud.models.slide_export_format import SlideExportFormat
from asposeslidescloud.models.shape import Shape
from asposeslidescloud.models.fill_format import FillFormat
from asposeslidescloud.models.line_format import LineFormat
from asposeslidescloud.models.text_frame_format import TextFrameFormat
from asposeslidescloud.models.three_d_format import ThreeDFormat
from asposeslidescloud.models.shape_bevel import ShapeBevel
from asposeslidescloud.models.light_rig import LightRig
from asposeslidescloud.models.camera import Camera
slides_api = SlidesApi(None, "my_client_id", "my_client_secret")
file_name = "example.pptx"
slide_index = 1
dto = Shape()
dto.shape_type = "Rectangle"
dto.x = 100
dto.y = 100
dto.height = 100
dto.width = 200
dto.text = "Sample text"
dto.fill_format = FillFormat()
dto.fill_format.type = "NoFill"
dto.line_format = LineFormat()
dto.line_format.fill_format = FillFormat()
dto.line_format.fill_format.type = "NoFill"
text_frame_format = TextFrameFormat()
text_frame_format.transform = "ArchUpPour"
three_d_format = ThreeDFormat()
bevel_bottom = ShapeBevel()
bevel_bottom.bevel_type = "Circle"
bevel_bottom.height = 3.5
bevel_bottom.width = 3.5
three_d_format.bevel_bottom = bevel_bottom
bevel_top = ShapeBevel()
bevel_top.bevel_type = "Circle"
bevel_top.height = 4
bevel_top.width = 4
three_d_format.bevel_top = bevel_top
three_d_format.extrusion_color = "#FF008000"
three_d_format.extrusion_height = 6
three_d_format.contour_color = "#FF25353D"
three_d_format.contour_width = 1.5
three_d_format.depth = 3
three_d_format.material = "Plastic"
light_rig = LightRig()
light_rig.light_type = "Balanced"
light_rig.direction = "Top"
light_rig.x_rotation = 0
light_rig.y_rotation = 0
light_rig.z_rotation = 40
three_d_format.light_rig = light_rig
camera = Camera()
camera.camera_type = "PerspectiveContrastingRightFacing"
three_d_format.camera = camera
text_frame_format.three_d_format = three_d_format
dto.text_frame_format = text_frame_format
# Create the WordArt object and download the presentation.
slides_api.create_presentation(file_name)
slides_api.create_shape(file_name, slide_index, dto)
file_path = slides_api.download_file(file_name)
The WordArt object in the output presentation:
This is a paid product but you can make 150 free API calls per month for API learning and presentation processing.
I work as a Support Developer at Aspose.

Get keypair from seed

I have waves full node on my server.
Using REST API I've generated a few addresses(like POST /addresses).
With REST API I can get encoded seed for each of this address, for example
GET /addresses/seed/<address>
{
"address" : "address",
"seed" : "seed_value"
}
But to send money from those addresses I need a corresponding private key.
So how can i get it?
Ok, as it turned out in this thread - https://forum.wavesplatform.com/t/question-about-addresses-endpoint/7752, each address is generated using the same seed with prepended bytesarray (for example: for a first address - [0x00, 0x00, 0x00, 0x00]).
Bytesarray is incremented after each address creation.
So, instead of using seed from addresses/seed/<address>, had to use seed from wallet/seed
This one works in python(using pywaves)
import axolotl_curve25519 as curve
import base58
import hashlib
import sha3
import pyblake2
import struct
import pywaves
def hashChain(noncedSecret):
b = pyblake2.blake2b(noncedSecret, digest_size=32).digest()
return sha3.keccak_256(b).digest()
seed = "value from /wallet/seed"
nonce = struct.pack(">L", 40)
seedHash = hashChain(nonce + base58.b58decode(seed))
accountSeedHash = hashlib.sha256(seedHash).digest()
private_key = base58.b58encode(curve.generatePrivateKey(accountSeedHash))
address = pywaves.Address(privateKey=private_key)
P.S. I'm pretty sure that don't understand how address' seed must be interpreted/used "in the right way", but I didn't find any documentation related to this. If someone know how to use it - I will be really appreciated.

Kraken API "Invalid signature" error using Matlab

I am trying to implement the API of the bitcoin exchange Kraken in MATLAB. Unfortunately I got stuck at trying to execute an authentication in order to retrieve private user data.
In particular, I was playing with the following Implementation: Kraken API MATLAB client invalid signature error. The documentation of Kraken's API is here: https://www.kraken.com/help/api
When connecting with the Private user data but I continuously run into the error: {"error":["EAPI:Invalid signature"]}. Could someone maybe have a quick look at the implementation below and look for flaws in the code? Or has someone successfully implemented the Kraken API for Matlab?
Many thanks!
% Private
uri = '0/private/Balance';
postdata='';
[response,status] = kraken_authenticated(uri,postdata)
% test uri='0/private/AddOrder'
% test postdata='&pair=XBTEUR&type=buy&ordertype=limit&price=345.214&volume=0.65412&leverage=1.5&oflags=post'
function [response,status]=kraken_authenticated(uri,postdata)
% Generate URL
url=['https://api.kraken.com/',uri];
% nonce
nonce = num2str(floor((now-datenum('1970', 'yyyy'))*8640000000));
key = ' '
secret = ' '
% 1st hash
Opt.Method = 'SHA-256';
Opt.Input = 'ascii';
sha256string = DataHash(['nonce=',nonce,postdata],Opt);
% 2nd hash
%sign = crypto([uri,sha256string], secret, 'HmacSHA512');
sign = crypto([uri,sha256string], base64decode(secret), 'HmacSHA512')
%sign = HMAC([uri,sha256string], base64decode(secret), 'SHA-512');
%header_0=http_createHeader('Content-Type','application/x-www-form-urlencoded');
header_1=http_createHeader('API-Key',key);
header_2=http_createHeader('API-Sign',char(sign));
header=[header_1 header_2];
[response,status] = urlread2(url,'POST',['nonce=',nonce,postdata],header);
end
function signStr = crypto(str, key, algorithm)
import java.net.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import org.apache.commons.codec.binary.*
keyStr = java.lang.String(key);
key = SecretKeySpec(keyStr.getBytes('UTF-8'), algorithm);
%key = SecretKeySpec(keyStr.getBytes(), algorithm)
mac = Mac.getInstance(algorithm);
mac.init(key);
toSignStr = java.lang.String(str);
signStr = java.lang.String(Hex.encodeHex( mac.doFinal( toSignStr.getBytes('UTF-8'))))
%signStr = java.lang.String(Hex.encodeHex( mac.doFinal( toSignStr.getBytes())))
end
function header = http_createHeader(name,value)
header = struct('name',name,'value',value);
end
I'm actually trying to do my owm implementation in c++, and I was here for another error I get, but here is a possible cause I noticed in your code :
The first sha256 hash should be of a concatenation of nonce and postdata. As postdata is also containing the nonce, if the nonce value is 123456789, then you should do (pseudo-code) :
sha256("123456789nonce=123456789")
or in Matlab :
sha256string = DataHash([nonce,'nonce=',nonce],Opt);
I hope it helps.

My web app on Yesod, Auth-HashDB, and PostgreSQL refuses to compile -- Couldn't match type ‘AuthEntity App’ with ‘User’

I've been trying to give myself a crash course in Yesod, but I can't seem to figure out what I'm doing wrong here. It's likely a conceptual failing, but I've more-or-less copy-pasted the code available on various short introductions to HashDB in an attempt to make a hashed DB authentication system, but no dice.
Foundation.hs:136:23:
Couldn't match type ‘AuthEntity App’ with ‘User’
In the expression: getAuthIdHashDB AuthR (Just . UniqueUser) creds
In an equation for ‘getAuthId’:
getAuthId creds = getAuthIdHashDB AuthR (Just . UniqueUser) creds
In the instance declaration for ‘YesodAuth App’
From each segment of code that's relevant:
config/models:
User
name Text
password Text Maybe
UniqueUser name
Model.hs:
import Yesod.Auth.HashDB (HashDBUser, userPasswordHash, setPasswordHash)
import Database.Persist.Quasi (lowerCaseSettings)
...
share [mkPersist sqlSettings, mkMigrate "migrateAll"]
$(persistFileWith lowerCaseSettings "config/models")
instance HashDBUser User where
userPasswordHash = userPassword
setPasswordHash h u = u { userPassword = Just h }
Foundations.hs:
...
import Yesod.Auth
import Yesod.Auth.HashDB (authHashDBWithForm, getAuthIdHashDB, authHashDB)
import Yesod.Auth.Message (AuthMessage (InvalidLogin))
...
instance YesodAuth App where
type AuthId App = UserId
loginDest _ = HomeR
logoutDest _ = HomeR
redirectToReferer _ = True
authPlugins _ = [ authHashDB (Just . UniqueUser) ]
getAuthId creds = getAuthIdHashDB AuthR (Just . UniqueUser) creds
authHttpManager = getHttpManager
Any help would be appreciated. I still kind of suck at Haskell, so this is also my attempt at a crash course in it as well.
This typically means that you don't have an AuthEntity associated type declared, which in turn means that you don't have a YesodAuthPersist instance. In your case, this is probably just:
instance YesodAuthPersist App where
type AuthEntity App = User
This is provided by the Yesod scaffolding.

Something wrong with my socket program

I wrote a program communicated with sockets.But I don't know why they don't work.
Server Code:
this.serverSocket = new ServerSocket(ServerConnector.port);
this.socketListener = this.serverSocket.accept();
System.out.println(this.socketListener.getPort());
this.objIn = new ObjectInputStream(this.socketListener.getInputStream());
System.out.println("1");
this.objOut = new ObjectOutputStream(this.socketListener.getOutputStream());
System.out.println("1");
this.objOut.writeInt(19999);
System.out.println("1");
this.objOut.writeObject(new Date());
System.out.println("1");
Client Code:
this.clientSocket = new Socket(ClientConnector.host, ClientConnector.port);
System.out.println(this.clientSocket.getPort());
this.objIn = new ObjectInputStream(this.clientSocket.getInputStream());
System.out.println("1");
this.objOut = new ObjectOutputStream(this.clientSocket.getOutputStream());
System.out.println("1");
int i = (Integer) this.objIn.readInt();
System.out.println(i);
Date date = (Date) this.objIn.readObject();
The truth is, they don't show any information I suggested to pass through(19999 and date), they even can't print a line of "1"(I added for testing). It means even the line below can't work normally. I really confused by these, who can figure the error out?
this.objIn = new ObjectInputStream(this.clientSocket.getInputStream());
You are most likely experiencing the effect of Nagle's Algorithm. which tries to optimize packet sending in TCP. If you want to send your data immediately you need to disable it using the setTcpNoDelay method on the socket interface.
P.S. no idea why the question is tag'ed as osgi, as it has no relevance to OSGi at all.